How to update the ServiceNow RITM worknotes and state values through Scripted REST API POST ?

ITSM ServiceNow
Kilo Explorer

Requirement:
We have a service catalog form and it has one list collector field with 20 values.

Whenever user submits this catalog form via service catalog portal it should hit the third party application with those 20 values.

Based on the request received, the third party application should process those 20 values and sends( may be after 2 hours) the response back to ServiceNow to update the particular RITM worknotes and state as well based on the response received from third party application.

-----------------------------------------------------------------------------------------------------------------------------------------------

I did the below to achieve the above requirement:

We have a service catalog form and it has one list collector field with 20 values.

--> For this, I have created ServiceCatalog form.

 

Whenever user submits this catalog form via service catalog portal it should hit the third party application with those 20 values.
--> For this, I am calling third party REST API from the catalog form workflow "run script" activity for sending 20 values to third party application.


Based on the request received, the third party application should process those 20 values and sends( may be after 2 hours) the response back to ServiceNow to update the particular RITM worknotes and state as well based on the response received from third party application.
--> For this, I have created Scripted REST API POST to receive the response from Third party application.

Now the question is below:

I want to know how to update the ServiceNow RITM worknotes and state values based on the response received from third party application through ServiceNow Scripted REST API POST method.

What is the best method to do this without impacting the ServiceNow platform ?

9 REPLIES 9

Mike15
Tera Contributor

Hey @ITSM ServiceNow Developer 

Hey How you able to achieve this 

Req is Based on the response code success or failure we need to update the State of the RITM  through scripted rest API ?

 

Any Idea ?

@Ankur Bawiskar 

Hi,

you should be able to update the state of RITM via scripted REST API

Regards
Ankur

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

Hello @Ankur Bawiskar 

I need to update the state if the response code is success then state should be close completed and workflow should end or if the response code is failure then state should be in-progress and create a manual task ,it is done based on the script you helped 

var corrId = 'Correlation ID '; 
var responseCode = 'Response Code';
var requestBody = request.body.dataString;
var parser = new JSONParser(); 
var parsedData = parser.parse(requestBody);
var ID= parsedData[corrId]; //We are parsing the correlation id and storing in the id field to query the Incident table 
 responseCode = parsedData[responseCode];
var gr = new GlideRecord('incident');
gr.addQuery('correlation_id', ID); // We are querying the incident table to match the correlation id in the Incident table and update the Work notes 
gr.query(); // Found the correlation id in the Incident Table 
if(gr.next()){
gr.work_notes = responseCode; // Update the Work notes with the response code 
gr.update();
response.setStatus(200);
   } else {
 response.setStatus(404);
    }

task ,it is done based on the script you helped 

 

Hi,

Would you mind creating a new question as this is quite older one.

Do tag me so that I can help

Regards
Ankur

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

Hello @Ankur Bawiskar 

https://community.servicenow.com/community?id=community_question&sys_id=ae517d20dbdca4104aa5d9d9689619b9