Pass the JSON payload as inputs to a flow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2025 01:53 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2025 02:01 AM
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
3) Now how to use script step to know conflict, see the UI action of "Check Conflicts" on CHG table
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2025 03:14 AM
Ok ANkur,
Thanks for your timely response.
I will create a CR and come back to you if am Stuck
Regards,
Lucky
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2025 04:17 AM
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:
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:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2025 04:28 AM
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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader