How to use Scripted get rest api in servicenow

Kishor O
Tera Sage

My requirement is I need to get all the active incidents from Instance A and Store those values in the custom table of instances B.

*Custom table has 4 fields (u_number, u_inc_short_descriptio, u_inc_description, u_inc_channel) I have to set these field values to the response from instance A get method.

*Please suggest to me how I can achieve this using scripted rest api.

with ServiceNow instance A and ServiceNow instance B

1 ACCEPTED SOLUTION

Why not? There we go.

sm.setEndpoint('<instance_name>/api/now/table/incident');
sm.setHttpMethod('GET');
sm.setQueryParameter("sysparm_query","active=true");
sm.setQueryParameter("sysparm_fields","number,short_description,description,contact_type");
var response = sm.execute();
var responseBody = response.getBody(); //this is return an object contains result array of incidents

 

So from the Instance B, we can leverage the method GET to pull the data from the Instance A.

View solution in original post

7 REPLIES 7

@Kishor O 

Not at all. Just use the OOTB ones for your case.

You can also play with other APIs within the REST API Explorer in ServiceNow.

URL: https://<instance_name>/$restapi.do

 

The one from my comments is Table API.

Screenshot 2023-10-11 at 14.35.23.png

 

ServiceNow Developer Table API Reference

 

Cheers,

Tai Vu

 

@Tai Vu 

Can we use the script include in Instance B to set Values in the custom table  by calling get method from Instance A ?

Why not? There we go.

sm.setEndpoint('<instance_name>/api/now/table/incident');
sm.setHttpMethod('GET');
sm.setQueryParameter("sysparm_query","active=true");
sm.setQueryParameter("sysparm_fields","number,short_description,description,contact_type");
var response = sm.execute();
var responseBody = response.getBody(); //this is return an object contains result array of incidents

 

So from the Instance B, we can leverage the method GET to pull the data from the Instance A.