Creating incident record in a remote instance using scripted recordless REST api through Flow action

vamsi kuruvella
Tera Contributor

Why RecordLess REST API?

Generally, Outbound REST message seems easy but very confusing(Atleast to me). Good thing with RecordLess REST API is everything that you are doing will be at the same place and easy to read.

 

Steps:

1. Create a new flow action. I have named it as "RecordLess REST Action" 

vamsikuruvella_1-1677223169682.png

2. Create Flow action input as below. 

vamsikuruvella_5-1677225367756.png

 

3.Add Script Step to the flow action by clicking on the "+" in the action Outline. After adding the Script step create the input in the script step to get the incident record from the "inputs" step using data pill. And your flow action should look like below image.

vamsikuruvella_6-1677225459028.png

 

4. Paste the below code in the script portion in the flow action make sure to change the user name and password.

user name and password should be the user name and password of the user in the remote instance and make that user admin to make things easy.

 

 

 

 

 

(function execute(inputs, outputs) {
var endPoint='https://{instance number}.service-now.com/api/now/table/incident';
var resp={};
var inc=inputs.incident;
resp['description']=inc.description.toString();
resp['short_description']=inc.short_description.toString();

var req=new sn_ws.RESTMessageV2();
req.setEndpoint(endPoint);
req.setHttpMethod('POST');
var user = {Remote instance user name goes here};
var password = {Remote instance user password goes here};
req.setBasicAuth(user,password);
req.setRequestHeader("Accept","application/json");
req.setRequestHeader('Content-Type','application/json');
req.setRequestBody(JSON.stringify(resp));
var response = req.execute();
var out = response.getBody();
var outobj=JSON.parse(out);
outputs.tarnum=outobj.result.number;
outputs.targetsysid=outobj.result.sys_id;
 
})(inputs, outputs);

 

 

 

 

 

 

5. And create the outputs in the "script step" as below.

vamsikuruvella_3-1677224686083.png

 

6. Now we have to create the Flow action outputs. Create two new flow Action outputs as below and assign the value of the "script step" outputs to these outputs as shown below.

vamsikuruvella_4-1677225004575.png

 

7. Remember to Publish the flow action.

8. Testing!, Click on the "Test" button in the top right, select the record and Click "run test".

vamsikuruvella_7-1677229189261.png

 

9. Say I have selected "INC0010111" in current instance(dev144888) Which is 

vamsikuruvella_8-1677229334536.png

 

10. Will create the new Incident record in Remote incident(dev94584) which is 

vamsikuruvella_9-1677229423657.png

Tips:

1. .toString() should be used to convert the object to string in line 5&6

2. If you are confused on how I got the endpoint. You can watch the this video by BasicoServiceNow.

3. Don't use .execute() more than once it will create more records if you use it more than once(I made same mistake).

4. Make sure the Remote instance user has "admin" role. 

5. Make sure you activate the Integration Plugin in the Home page.

 

 

** "ServiceNow IntegrationHub Installer" plugin should be Activated to get the "Rest Step" in Flow Designer.

vamsikuruvella_15-1677230904393.png

Ping me if you are stuck anywhere. I will try to resolve.

#Integration #scripting #Flow Designer

 

 

 

 

0 REPLIES 0