How to read nested collection response from Webservice and insert into CRM?

Hi Team,

We are using an OOTB Webservice section to call the (GET) REST API endpoint and the response collection is captured in the "Response Parameter" of that web service. The response has a nested collection of data.
 

We are currently using the Script task to read the response data of a web service. Now it is required to get into the nested data set further and any insight on this would be helpful.

STEP 1: Web service Response

 

STEP 2: Script task to read web service response

var deliveries = Get<ICompositeObjectList<ICompositeObject>>("WebService1.Output_Out");
foreach(var delivery in deliveries){
//Delivery is again a nested data
//need to loop through the delivery (has parent record info and array of child record details)
}
 

Webservice Output:

{
   "output":[
      {
         "challan":[
            {
               "delivery_number":"DEL-251-253423",
               "delivery_id":1151109,
               "lines":[
                  {
                     "order_number":2011010049349,
                     "item_code":"RT3060-002GRL",
                     "grade":"A"
                  },
                  {
                     "order_number":2011010049359,
                     "item_code":"RT3062-002GRL",
                     "grade":"A"
                  }
               ]
            },
            {
               "delivery_number":"DEL-251-253430",
               "delivery_id":1151109,
               "lines":[
                  {
                     "order_number":2011010049369,
                     "item_code":"RT3060-002GRL",
                     "grade":"B"
                  },
                  {
                     "order_number":2011010049379,
                     "item_code":"RT3062-002GRL",
                     "grade":"B"
                  }
               ]
            }
         ]
      }
   ]
}

Need to traverse through the nested collection and one of the properties in the collection of values is array too {like section record information & Child record information} and then insert them into CRM table (Parent and child). Insight for processing this data set would be helpful.

 

 

 

Best Regards,
Bhoobalan Palanivelu.

Like 0

Like

3 comments
Best reply

Hello,

In order to process the collection inside a collection, you need to do the following:

1) In the process, create a new parameter and add values to it from the web server response:

 

 

2) In your script task, you need to proceed this parameter and get values from it.

Dmytro Vovchenko,

Thanks for the information shared.
We were able to achieve processing the multiple nested collection through the below script and insert the Parent/Child collection sequentially.

 

List<object> deliveryItem = new List<object>();
List<object> lineItem = new List<object>();
var serviceOut = Get<ICompositeObjectList<ICompositeObject>>("Output");
 
foreach(ICompositeObject chall in serviceOut){
	if(chall.TryGetValue<ICompositeObjectList<ICompositeObject>>("Challan" , out ICompositeObjectList<ICompositeObject> curChallan)){
		foreach(ICompositeObject _challan1 in curChallan){
				curChallan1.TryGetValue<string>("Driver_contact_no" , out string Driver_contact_no); 
				deliveryItem.Add(Driver_contact_no);
 
				if(_challan1.TryGetValue<ICompositeObjectList<ICompositeObject>>("Lines" , out ICompositeObjectList<ICompositeObject> curLines)){
					foreach(ICompositeObject _Lines1 in curLines){
							_Lines1.TryGetValue<decimal>("Secondary_quantity_ctn" , out decimal Secondary_quantity_ctn); 
							lineItem.Add(Secondary_quantity_ctn);
				}	
			}
		}
	}
}

 

Also, we can utilize this without performing the Step 1 of Creating Nested Parameter Collection in Parameters of Business Process. Since the Web-Service already has the response parameter of same. But the parameter name from Webservice is always with a suffix _OUT

Iteration of Composite object collection is done through by following the Type<> in below Interface
ICompositeObjectList<TObject>
Interface ICompositeObject

 

 

 

BR,
Bhoobalan Palanivelu.

Show all comments