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

Hello ANkur,

 

Yes, now I am able to create a change request from Scripted REST API, but please guide me from here to achieve my goal.

Next to be checked is,

If the created CR has any conflict detected, then there is a conflict_status field available on change request and it shows, Conflict. So, here I also want to show the customer the response like, Change has been created with CHG0012345 but there is a conflict detected, 

and then I need to check the Upcoming schedule entry which cannot create conflict again and show that to the customer.

 

Can you guide me here?

 

For your reference, I am pasting my Scripted REST API code:

Lucky1_0-1748277809410.png

Lucky1_1-1748277878839.png

 

 

Regards,

Lucky

 

 

@Lucky1 

I already told how to do that above.

see this

AnkurBawiskar_0-1748278259113.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

Yes Ankur,

 

You told me that, Thanks a lot for that But I am trying to get in detail to understand better.

like,

1, create a custom action and call it in the sub flow (here I am trying to find what logic can be written and what out puts should I get)

2. Secondly, if I glide record the table "Shedule entry" to find out next scheduling start date and update the aready created record to see if there will be no conflict, then I need to return the response to the customer.

But unfortunately, I am not aware of how to do this.

 

 

 

 

 

Thanks and Regards,

Lucky

@Lucky1 

that custom flow action will have script step

which script to use refer the OOTB UI action for Check Conflicts and then take it from there.

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

Hello Ankur,

 

Lucky1_0-1748330847023.png

 

In line number 6, I am getting the created Change request sys_id

but in line number 17, I am getting the Row count as 0.

 

When I write the same script in scripts background, by hard coding the sys_id, then it is giving the right value.

Actually in the line number 13, I have updated like this,

gs.log("Check for conflicts ACTION Row count is "+gr.getRowCount()+gr.change+" "+change_sys_id);
 
it is giving row count as 0, and gr.change as undefined, and the change_sys_id is giving right sys_id value

 

 

Where it went wrong here?

 

 

 

Regards,

Lucky