Skip to Content
Technical Articles

Creating a Lead from a Business Partner via ABSL Coding

Creating a Lead from a Business Partner using the Standard Action “CreateFromBusinessPartner()”

 

Scenario:

You want to Create Leads from a Business Partner using the SAP Cloud Applications Studio.

In this example we will be using a Custom Business Object which will trigger the creation of the Lead using the CreateFromBusinessPartner() action that is part of the LeanLead Business Object and follow-up with some modification of the lead using the Standard Extended Lead Business Object.

It is important to note that the LeanLead Business Object is a shell around the Lead Business Object which additionally combines the related customer and contact data however it does not contain its own persistency which means that the Object should never be accessed directly as it could lead to unexpected results instead the Lean Object should be used to retrieve the required instance.

 

Pre-requisites:

  • First of all we need to ensure that we have a Business Partner that is correctly assigned to a Sales Organization.
  • You have extended the Standard “Lead” Business Object and created the After-Modify script.
  • To use the association “to Customer” orĀ  query the Customer object you need to import the AP.FO.BusinessPartner.Global namespace.
  • To use the CreateFromBusinessPartner() function you need to import the AP.CRM.Global; namespace.

 

Step by Step Creation:

Before we create the lead, we have to retrieve the Business Partner which we are planning to use for the creation of the lead, here are two examples of how this can be done:

 

We can retrieve the Business Partner either directly:

Customer.Retrieve(UUID of Business Partner);

 

or in-directly by using a Query as seen below:

Custom BO - ABSL Coding:

//Retriving the Business Partner using a Query
var QueryCustomer=Customer.QueryByIdentification;
var CustSelParams=QueryCust.CreateSelectionParams();
CustSelParams.Add(QueryCust.InternalID,"I","EQ","12345"); //12345 is the ID of the Business Partner
var CustResult=QueryCust.Execute();
this.toCustomer=CustResult.GetFirst(); // Here we are passing the result of the Query to the association


//Now lets create the Lead using the retrieved Business Partner
var newLead = LeanLead.CreateFromBusinessPartner(this.toCustomer); 

// !!! NOTE !!! 
//Using just this function without the After-Modify event
//will fail with an error "Name-Content missing"
//as this function does not provide a way to fill the name 
//of the newly created Lead.
//To fill the name of the Lead we have to do create an
//After-Modify script on the Lead Business Object as follows.

 

Extended Lead BO - After-Modify Coding:
//To ensure we only pass the name of a Lead that is being created via ABSL
//as by default every Lead has to have a name defined.
If(this.GetFirst().Name.content.IsInitial()) {  
this.GetFirst().Name.content="Our New Lead"; //This will set the name of our newly created lead
//At this point we can also define any other details we wish to include in our newly created lead
//This script is triggered before the CreateFromBusinessPartner() function completes its execution cycle.
}

 

After executing the ABSL Code logic we can observe our newly created Lead!

 

Voila you have successfully created a Lead From a Business Partner using the SAP Cloud Applications Studio and some ABSL scripts.

It is worth noting that the Creation of the Lead itself will extend the processing time of the event, hence the execution time will definitely be noticeable, therefore to optimize the ABSL script performance it is a good idea to use the After-Modify event to fill in all the required data for the newly created lead to prevent fetching it once again at a later time using a query.

 

Be the first to leave a comment
You must be Logged on to comment or reply to a post.