Skip to Content
author's profile photo Former Member
Former Member

Error does not display on first click on Save button

Hi Team,

We are facing one issue after extending customer BO. Here we have applied the logic to auto assign the sales org of logged employee to new quick created account. Now we need to display the error message in case logged employee does not have sales org assigned or in case account is already exist then also it should display the error message.

I have implemented below logic but problem is that when I click on Save button first time it does not display the error message. It display the message when I click second time on save button.

.XBO code:

import AP.Common.GDT;

import AP.FO.BusinessPartner.Global;

[Extension] businessobject AP.FO.BusinessPartner.Global:Customer raises Error_Message_Emp, Error_Message_Sales {

message Error_Message_Emp text "Save Failed";

message Error_Message_Sales text "This Employee was not assigned to any sales org";

node AddressInformation {

}

node Common {

element IsCreated : Indicator = false;

}

node CurrentEmployeeResponsible {

}

}


Event: BeforeSave Code


import ABSL;

import AP.PC.IdentityManagement.Global;

import AP.FO.BusinessPartner.Global;

import AP.FO.MOM.Global;

import AP.Common.GDT;

import AP.CRM.Global;

var sa: elementsof SalesArrangement;

var sapt: elementsof SalesArrangement.PricingTerms;

var current_emp_uuid = Context.GetCurrentIdentityUUID();

var current_employee_name;

if (!this.CurrentCommon.IsCreated)

{

if (!this.InternalID.IsInitial())

{

var query = Customer.QueryByBusinessObjectCustomer;

var selectionParams = query.CreateSelectionParams();

var bp = this.InternalID;

  1. selectionParams.Add(query.InternalID, "I", "EQ", bp);

var results = query.Execute(selectionParams);

var count = results.Count();

if (count == 0)

if(!current_emp_uuid.content.IsInitial())

{

var bupa_uuid = Identity.Retrieve(current_emp_uuid).BusinessPartnerUUID;

if(!bupa_uuid.content.IsInitial())

{

var employee = Employee.Retrieve(bupa_uuid);

if(employee.IsSet())

{

Trace.Info(employee.CurrentCommon.Person.Name.GivenName);

var OrgUnit = employee.CurrentOrganisationalUnitAssignment.GetFirst();

if (!OrgUnit.IsSet())

{

this.CurrentCommon.IsCreated=false;

raise Error_Message_Sales.Create("E");

}

else

{

var OrgUnitNode = OrgUnit.ToParent;

var salesResp = employee.EmployeeSalesResponsibility.GetFirst();

var curr = OrgUnitNode.CurrentFunctions.CurrencyCode;

if (salesResp.IsSet())

{

Trace.Info(OrgUnitNode.ID);

sa.CustomerUUID=this.UUID;

sa.DistributionChannelCode.content=salesResp.DistributionChannelCode.content; // direct sales

sa.DivisionCode.content=salesResp.DivisionCode.content;

var fu= FunctionalUnit.Retrieve(OrgUnitNode.ID);

if(fu.IsSet())

{

sa.SalesOrganisationUUID = fu.UUID;

sapt.CurrencyCode = curr;

var testInstance = SalesArrangement.Create(sa);

var testInsance1 = testInstance.PricingTerms.Create(sapt);

this.CurrentCommon.IsCreated=true;

}

}

}

}

}

}

}

else // If the customer already exists in the databse, no need to apply the logic validation onsave should be true

{

this.CurrentCommon.IsCreated=true;

}

}

}


Validation on save event code:


import ABSL;

if (!this.CurrentCommon.IsCreated)

{

return false;

raise Error_Message_Sales.Create("E");

raise Error_Message_Emp.Create("E");

}

else

{

return true;

}

Regards

Nitin

Add a comment
10|10000 characters needed characters exceeded

Related questions

4 Answers

  • Best Answer
    Posted on Mar 29, 2016 at 05:59 AM

    Hi Nitin,

    Have you debugged your codes?

    Quick tip :

    You should write "return" below "raise".

    raise Error_Message_Sales.Create("E");

    raise Error_Message_Emp.Create("E");

    return false;


    Best Regards,

    Fred

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Mar 30, 2016 at 03:52 PM

    Hi Fred and Sumeet,

    Thanks for your reply, In silver-light mode it is working fine. Could you please share your idea why it is not working in non-silverlight mode?

    I debugged it and can see the values are passing correctly in Save event.

    Regards

    Nitin

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Apr 04, 2016 at 01:12 PM

    Hi Sumeet and Fred,

    I am getting this issue in every browser. Although its not consistence for few users. For few user it works 1 - 2 times then again start same behavior. issue is with HTML mode not with Silverlight. Could you guys please advise on this.

    Regards

    Nitin.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 21, 2016 at 05:57 PM

    Hi Nitin,

    I need to do something similar... I need to assign a sales area when I create a new Customer.

    I took your code as an example for my sales area code assign ..

    var sa : elementsof SalesArrangement; var sapt: elementsof SalesArrangement.PricingTerms;

    sa.CustomerUUID = this.UUID;

    sa.DistributionChannelCode.content = "MY_DIST_CHANNEL_CODE"; sa.DivisionCode.content= "MY_DIV_CODE"; var fu = FunctionalUnit.Retrieve("MY_SALESAREA_ID");

    if (fu.IsSet())

    {

    sa.SalesOrganisationUUID.content = fu.UUID.content;

    var testInstance = SalesArrangement.Create(sa);

    sapt.CurrencyCode = "ARS";

    var testInsance1 = testInstance.PricingTerms.Create(sapt);

    var CustomerSalesArrangement = this.SalesArrangement;

    CustomerSalesArrangement.Add(testInstance);

    }

    But my problem is , when I put this code , the before_save event is executed many tines.. it is like if it entered in a infinite loop.. And it never saved the new customer.

    thanks in advance,

    Elina

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.