For Each Item flow logic how to get the consolidated output

Jamsheer1
Tera Guru

while creating a record I need to get related list of records and perform a REST action for each record . I'm using this flow and its working fine however I've no idea how we can get the final output to a variable.

Basically each REST response will return an unique reference and I wanted to update the concatenate value of response to a field in the table.

find_real_file.png

jamsheer

8 REPLIES 8

Hitoshi Ozawa
Giga Sage
Giga Sage

Had a similar situation.

One way is to update the table in each iteration.

The other way that I took was to move the for loop into a Script step in Custom Action. Instead of using Flow's REST call, I copy & pasted REST script generated by creating a REST Message.

https://docs.servicenow.com/bundle/orlando-application-development/page/integrate/outbound-rest/task/t_ConfiguringARESTMessage.html

Muralidharan BS
Mega Sage
Mega Sage

Hi Jamsheer,

You can try the below. I assume that you are going to update the short description field of change. create a output to the flow only for the rest value. create a step below the Rest call to update the record and try this script in the short description. Amend the 2nd line. 

var nowShortDesc = ParseInt(fd_data.current.short_description);
var addShortDesc = ParseInt(fd_data._rest_step.valueid);
return nowShortDesc+addShortDesc;

 

If you like to go without script, then you can add lookup record to search that record and concatenate the value like below. step 5 is lookup and step 6 is to update the short description. 

 

short description = Lookup record's short descrption + rest message output; [I dont have rest step here so I pulled step 4 short description]

 

find_real_file.png

 

 

Thanks

 

Thank you Murali, I was able to get the results based on your input however I was looking for a solution which doesn't update the target record multiple times. Let's say if the CI list has 100 records then the CHG record get's updated 100x which may not be a good idea .

Hi Jamsheer, 

Try this it may work, add an action with script step below the rest call, take input as response from rest msg and output is concatenated value. 

Finally, add update the record after the for loop and drag the output from script step. Below image may help you. 

 

find_real_file.png