- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2021 12:08 PM
We have two instances(A nd B) and we are creating incidents in one(B) and creating incident for same on other instance(A) using a business rule and using post method
request.setEndpoint('https://instanceA-service-now.com/api/now/table/incident');
request.setHttpMethod(‘POST’);
We are sending the sys-id of incident created as well to instance A so that i can make a connection back and use it to update the record in future using the sys id with other record information
And we are able to send the data and create incident at instance(B)
Now we want to update the incident on instance(B) based on changes in instance(A)
We are using the business rule
request.setEndpoint('https://InstanceB.service-now.com/api/now/table/incident/bfbc42812f9d20107c652e5df699b63f'/'');
request.setHttpMethod('PUT');
this sysid is of the incident record i created on instance B and brought the value here to Instance A and using to make a connection back for update
But we are not able to set the dynamic value of sys-id it only works when i use hardcode value as mentioned above
Connection is there but we can’t execute using the dynamic value
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2021 12:27 PM
Hi jugnu,
The end point is a simple string that can be constructed if you have the desired value available. What if you try appending the target sys_id to your endpoint. Something like this:
var targetID = current.other_sysid;
var ourEndpoint = 'https://InstanceB.service-now.com/api/now/table/incident/';
var ourREST = new sn_ws.RESTMessageV2();
//option 1
ourREST.setEndpoint(ourEndpoint);
ourREST.setEndpoint(ourREST.getEndpoint() + targetID);
//option2
ourREST.setEndpoint(ourEndpoint + targetID);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2021 07:44 AM
Hi,
Since I have my authentication in an existing rest message in the system, do I need to pass the login information? Or can I call that GET rest message and put my own end point there? Or can I append the existing end point that is in that rest message?
Thank you for your assistance.
Stacy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2021 08:03 AM
Absolutely, Stacy! That's one of the great things about the reusable REST Message elements. You can call the message and the specific method by name. This utilizes any associated authentication and saves you from having to put that into your script. Here's how I typically form a script that uses a pre-defined REST message.
var myTarget = 'string%20target%20with%20no%20spaces'; // replace this string with whatever your target is (e.g. if calculated or from script)
var response;
var requestBody;
var responseBody;
var status;
var RESTCall;
try{
RESTCall = new sn_ws.RESTMessageV2("String name of REST Message", "String Name of Method");
RESTCall.setEndpoint(RESTCall.getEndpoint() + myTarget); // this uses the predefined endpoint from the method and appends my specific target
RESTCall.setHttpTimeout(10000); //In milliseconds. This one waits at most 10 seconds for response from http request.
response = RESTCall.execute();
responseBody = response.haveError() ? response.getErrorMessage() : response.getBody();
status = response.getStatusCode();
}
catch(ex) {
responseBody = ex.getMessage();
status = '500';
}
finally {
requestBody = RESTCall ? RESTCall.getRequestBody():null;
}
gs.log('requestBody: ' + requestBody, 'REST log');
gs.log('responseBody: ' + responseBody, 'REST log');
gs.log('status: ' + status, 'REST log');