on 03-29-2016 6:32 AM
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;
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
90 | |
10 | |
10 | |
10 | |
7 | |
7 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.