Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
ashishsingh1987
Employee
Employee
Hi,

Many a times, while integrating or passing the data to the 3rd party system from the Sales/Service cloud we are required to pass the data in the JSON format via ABSL script.

Constructing JSON format data via ABSL script for a deep entity structure,  e.g. Order Header & Item in a single call can be difficult.

Recently I had a similar requirement to pass the Header and Item data together to 3rd party system to create an Order.

Below are the steps I followed to achieve it. Hopefully it can be of some help to someone having similar requirement.

Note: Body of the Item or the header will vary case to case. Below data is only for understanding purpose.

Step 1: Construct each node separately. E.g. Construct Item structure in JSON format separately and store it in a string variable.


Similar approach can be applied for the other node structures.

 

Step 2: Once all the item or node level structures are ready, construct the complete body of the message to be passed. The complete body would usually combine the Header data and the other node item as shown below.

Here currently only Item node is shown as an example to be added to the header data.


 

 

On Execution, the values in the variable would be formatted as per JSON format.

Item JSON structure


 

Complete Body JSON structure (Header + Item )


P.S. The blog is only about an approach of constructing the JSON body (Header + item together ). Calling of each Rest API varies, depends on the credentials and other parameters as would be provided by the 3rd party system.

Also attached is the code snipped highlighted in the screenshots above. One can copy and modify it as per their body structure.
Item JSON format Code:

var items = "";
var itemsCount = this.ProductDetails.Count();
var count = 0;
var s = "";
foreach (var item in this.ProductDetails)
{
count = count + 1;
var itemNum = count.ToString();
item.ItemNo = itemNum;

s = "{" + "\"itemNumber\": \"" + item.ItemNo +
"\",\"brand\": \"" + item.BrandDesc +
"\",\"material\": \"" + item.ProductID.content +
"\", \"stockQuantity\": \"" + item.Quantity.ToString().Trim() + "\"" +
"}";

items = items + s;
//count = count + 1;

if (count != itemsCount)
{
items = items + ",";
}

}

Header+Item JSON format Code:

Body = "{ \"calledFor\": \"" + calledFor + "\", \"orderType\": \"" + this.OrderTypeDropDown_new +
"\", \"distChannel\": \"" + this.DistributionChannelDropDown_new +
"\", \"chequeRTGS\": \"" + this.ChequeRTGS.GetDescription() +
"\", \"chequeRTGSDate\": \"" + this.ChequeRTGSDate.ToString().Replace("-", "") +
"\", \"dealerCode\": \"" + this.AccountID +
"\", \"discountCode\" : \"" + discountCode +
"\", \"discountValue\" : \"" + discountValue +
"\", \"plant\" : \"" + this.Plant +
"\", \"draftOrder\": \"N\"," +
"\"draftOrderID\": \"\"," +
"\"itemDetails\": [" +
items + "]" +
", \"returnMessages\": []" +
", \"orderCreated\": []" +
"}";

Regards,

Ashish Singh
1 Comment