Pass the JSON payload as inputs to a flow

Lucky1
Tera Guru

Hello all,

 

I have created a scripted REST API, and in it, I have written a code like this,

var reqbody = request.body.dataString();

var parsedData = JSON.parse(reqbody);

 

try{

var inputs = {

"start_date" : parsedData.start_date.toString(),

"end_date" : parsedData.end_date.toString(),

"short_description" : parsedData.short_description.toString()

};

}

 

So, here now, I need to create these below steps: 

1. I need a create a flow using flow designer, where I need to create a change request from the inputs of the above scripted REST API, Hence, I need to call the flow from the Scripted REST API itself and pass the inputs to create the CR.

 

2. After a CR has been created, then I need to validate change conflicts where the conflicts are currently returning from a script include, 

If the script include returns like conflict detected, then I need to return the conflict type to the customer.

 

3 rd point I will try once I got to know how to achieve the above two points.

 

So, can someone please help me step by step how to do this?

 

 

Thanks a lot

 

 

 

Regards,

Lucky

 

10 REPLIES 10

Ankur Bawiskar
Tera Patron
Tera Patron

@Lucky1 

Steps you need to follow

1) get the values from JSON by parsing it

2) create subflow and pass those inputs to subflow and subflow will create CHG and it will use Custom Flow Action with script step to determine the conflict.

The subflow will have 1 output that is the conflict type. Make the subflow run in foreground so that you can get the conflict status and pass as API response to scripted REST API call.

Scripting with Flows, Subflows, and Actions 

AnkurBawiskar_0-1748249811230.png

 

3) Now how to use script step to know conflict, see the UI action of "Check Conflicts" on CHG table

AnkurBawiskar_1-1748250051632.png

 

If my response helped please mark it correct and close the thread so that it benefits future readers.

 

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Ok ANkur,

 

Thanks for your timely response.

I will create a CR and come back to you if am Stuck

 

 

Regards,

Lucky

Hello Ankur,

 

I have configured it, But when I try by clicking "Explore REST API" and I am passing cmdb_ci --- 'Sys_id'

It is saying "Flow object doesn't exist".

 

Can you help me please here?

 

My SCRIPTED REST API CODE:

Lucky1_0-1748258014362.png

Lucky1_1-1748258079326.png

Next I created a Sub flow and configured the inputs like,

ci

startDate

endDate

desc

sd

 

like what ever the keys are present in the scripted rest api

and also mapped the values using data pills in the flow in Create record action.

 

 

I am getting this error:

Lucky1_2-1748258248085.png

 

 

@Lucky1 

you are not calling subflow properly.

Please check the syntax and make the changes accordingly.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader