The CreatorCon Call for Content is officially open! Get started here.

How to replace these hard coded values with current values?

sriram9
Giga Contributor

Dear experts,

Here is my BR in my second servicenow instance, i wanted to replace the hard coded values(highlighted) of the code, so that , it takes the newly created incident's parameters(like current.short_description, current.impact etc) and transfers that to instance 1

request.setBasicAuth(user,password);
request.setRequestHeader("Accept","application/json");
request.setRequestHeader('Content-Type','application/json');

request.setRequestBody("{\"short_description\":\"created on 24-8-2018\",\"impact\":\"1\",\"urgency\":\"1\",\"description\":\"connected two servicenow instances and trying to pass data\"}");

var response = request.execute();
gs.log(response.getBody());
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
}

 

1 ACCEPTED SOLUTION

Chuck Tomasi
Tera Patron

BTW, I spent almost the entire session on today's community live stream on this same example. You can find it on YouTube on the Community Live stream 2018-08-27 show.

View solution in original post

7 REPLIES 7

Shweta KHAJAPUR
Tera Guru

Hi,

Copy the code from preview script Usage.

Hi,

I think in previous thread i have given the answer. Please Do as below,

try { 
 var r = new sn_ws.RESTMessageV2('RestTest', 'Post');
 r.setStringParameterNoEscape('short_description', current.short_description);

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

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

I have a question... i tried to use the "API explorer " in instance 1 to get the servicenow script and used it in instance 2's Business Rule created for the incident table.  I have not created any REST message.  whenever i create a new incident in instance 2, it creates a subsequent incident in instance 1, but the parameters are all hard coded.  Do i need to create a rest message if i have to integrate the two instances?  

Regards,

Sriram

Yes, You need to create RESTMessage because in the code provided by me RestTest is a Rest message name. If you create one REST message which you can use for all the CRUD operations. There you'll get clear idea about all operations and errors.