How to fetch single record using script "get rest message" from another instance?

Prathamesh Chav
Tera Contributor

Hi Team,

 

I am trying to fetch the record and I want it dynamically, so whenever I am selecting the record in instance 2, I want all the data of that record from instance 1.

 

I am using rest message for this and in get method I am trying to fetch the single record.

I am able to fetch all the records but I want single record only.

 

PrathameshChav_3-1739341576042.png

 

 

any changes I need to do in script?

 

I am able to pass the query parameters but not able to see them in the script?

 

PrathameshChav_2-1739341442050.png

 try { 
 var r = new sn_ws.RESTMessageV2('PDI Int Get data', 'Default GET');

//override authentication profile 
//authentication type ='basic'/ 'oauth2'
//r.setAuthenticationProfile(authentication type, profile name);

//set a MID server name if one wants to run the message on MID
//r.setMIDServer('MY_MID_SERVER');

//if the message is configured to communicate through ECC queue, either
//by setting a MID server or calling executeAsync, one needs to set skip_sensor
//to true. Otherwise, one may get an intermittent error that the response body is null
//r.setEccParameter('skip_sensor', true);

 var response = r.execute();
 var responseBody = response.getBody();
 var httpStatus = response.getStatusCode();
}
catch(ex) {
 var message = ex.message;
}

 

Can anyone help me in this?

 

Thank you

2 ACCEPTED SOLUTIONS

Ankur Bawiskar
Tera Patron
Tera Patron

@Prathamesh Chav 

you need to use Retrieve records API and pass the query

AnkurBawiskar_0-1739342232827.png

 

Use this to get only 1 record

AnkurBawiskar_1-1739342258248.png

 

You will also get code sample on how to consume it. this will help you when you consume it from other instance

AnkurBawiskar_2-1739342329947.png

 

No need of REST Message in other instance, directly use the above script and give correct authentication details.

I believe this much information is sufficient for you to start and enhance it further

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

View solution in original post

Community Alums
Not applicable

Hi @Prathamesh Chav 

To fetch single record from other instance, we have make our endpoint unique, make modification in REST Message with the GET method with following endpoint.

https://instance1.service-now.com/api/now/table/{table_name}/{sys_id}

 

View solution in original post

6 REPLIES 6

Ankur Bawiskar
Tera Patron
Tera Patron

@Prathamesh Chav 

Would you mind closing your earlier questions by marking appropriate response as correct?

Members have invested their time and efforts in helping you.

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

Ankur Bawiskar
Tera Patron
Tera Patron

@Prathamesh Chav 

you need to use Retrieve records API and pass the query

AnkurBawiskar_0-1739342232827.png

 

Use this to get only 1 record

AnkurBawiskar_1-1739342258248.png

 

You will also get code sample on how to consume it. this will help you when you consume it from other instance

AnkurBawiskar_2-1739342329947.png

 

No need of REST Message in other instance, directly use the above script and give correct authentication details.

I believe this much information is sufficient for you to start and enhance it further

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

@Prathamesh Chav 

Any update to my above comment?

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

Community Alums
Not applicable

Hi @Prathamesh Chav 

To fetch single record from other instance, we have make our endpoint unique, make modification in REST Message with the GET method with following endpoint.

https://instance1.service-now.com/api/now/table/{table_name}/{sys_id}