Technical Articles
Create Opportunity from Sales Order in C4C thru SAP Cloud Application Studio
Hi,
This blog will help you on how to create an opportunity from Sales Order header UI based on the user selection/requirement (button type custom UI field indicator(Yes/No) is added), thru the SAP Cloud Application Studio (PDI). Field indicator is created at tenant level and that would be imported into PDI (SDK) thru .ref object. You can also add another field to hold opportunity number in SO header UI for reference.
This process will be run during edit mode of SO.
Create a .XBO for extending CustomerQuote of AP.CRM.Global.
import ABSL;
import AP.CRM.Global;
import AP.Common.GDT;
import AP.PC.SalesTerritoryMgmt.Global;
if( this.CreateOpportunity && this.OpportunityNumber.IsInitial() ) {
// Get the account and ee responsible of the SalesQuote
var accountID;
var eeResponsible;
foreach(var p in this.Party) {
if(p.RoleCode == "1001") {
accountID = p.PartyKey;
}
if(p.RoleCode == "39") {
eeResponsible = p.PartyKey;
}
}
// Get the primary contact as well
var primaryContact = this.Party.MainPartyContactParty.GetFirst();
// Create the opportunity
var oppNode:elementsof Opportunity;
oppNode.Name.content = this.Name.content;
oppNode.ProcessingTypeCode = "OPPT";
var opp = Opportunity.Create(oppNode);
var opportunity = opp;
this.OpportunityNumber = opp.ID.RemoveLeadingZeros().content;
foreach(var p in opp.Party) {
// Set the account party id
if(p.RoleCode == "31") {
p.PartyKey = accountID;
// When there is a primary contact, set it
if(primaryContact.IsSet() && !primaryContact.PartyKey.PartyID.IsInitial()){
var partyContact = p.PartyContactParty.Create();
partyContact.PartyKey.PartyID.content = primaryContact.PartyKey.PartyID.content;
}
}
// Set an employee responsible
if(p.RoleCode == "39") {
p.PartyKey = eeResponsible;
}
}
// Set the Business Area - Sales Org
opp.SalesAndServiceBusinessArea.SalesOrganisationID =
this.SalesAndServiceBusinessArea.SalesOrganisationID;
// Set the Business Area - Dist Channel
opp.SalesAndServiceBusinessArea.DistributionChannelCode =
this.SalesAndServiceBusinessArea.DistributionChannelCode;
// Set the Business Area - Division
opp.SalesAndServiceBusinessArea.DivisionCode =
this.SalesAndServiceBusinessArea.DivisionCode;
}
Thanks
Chandra Gajula
Be the first to leave a comment
You must be Logged on to comment or reply to a post.