cancel
Showing results for 
Search instead for 
Did you mean: 

Error does not display on first click on Save button

Former Member
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

former_member200567
Active Contributor
0 Kudos

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

Former Member
0 Kudos

Yes I debugged It. even I have changed the code as per your tips but still same issue.

Regards

Nitin

former_member200567
Active Contributor
0 Kudos

Hi Nitin,

So, what is the value in this.CurrentCommon.IsCreated after first click  in Validation on-Save?

Best Regards,

Fred

sumeet_narang
Active Participant
0 Kudos

Hi Nitin,

Can you check how it behaves in Silverlight. Sometimes I have seen the error doesn't show up in the development tenants even though it does exist.

Regards,

Sumeet

Answers (3)

Answers (3)

Former Member
0 Kudos

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

Former Member
0 Kudos

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.  

former_member200567
Active Contributor
0 Kudos

Hi Nitin,

If that is the case, please raise an incident.

And ByD is not yet fully supported with HTML as far as I know.

Best Regards,

Fred

Former Member
0 Kudos

Hi Fred,

Thanks for your reply. I will raise an incident to SAP and will keep you guys updated.

Meanwhile please advise on my another thread:

Regards

Nitin

0 Kudos

Hi Nitin,

Any news about your problem? It seems like BeforeSave event doesn't run on the first (initial) save of the BO

Regards,

Alexey

Former Member
0 Kudos

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

sumeet_narang
Active Participant
0 Kudos

Hi Nitin,

This means that your code is fine.

This could be an issue with your browser. Can you try in some other browser, try Mozilla or maybe on some other system?

Regards,

Sumeet