How to call RestMessage from Include Script

AnishSasidharan
Mega Expert

Please let me know steps required for calling RESTMessage in business rule/ script include.

For example, i need to pass one parameter from business rule to RESTMessage.

so whether i need to create a parameter(without values) in REST function(post or put) ?

Many Thanks in Advance.

6 REPLIES 6

Jacob_Andersen
ServiceNow Employee
ServiceNow Employee

Interstingly enough, I do think this is a little confusing for people new to using the RESTMessage functionality. There are a couple of things that you need to do. First, create a new REST Message Function Parameter Definition. Give it a name (like Tiers) as well as a value that is a macro (like ${tiers} (see attached screenshot).

Once that is done, go to the bottom of the form and create a new REST Message Function Parameter. Here you should define a name (Tiers), type (String), and value (1,2,3). The value here is used when you do a test and is not to be considered a default value when you're using it via script (see attached screenshot).

Finally, you may now invoke this RESTMessage by using script like the following



var r = new RESTMessage('Forum Demo', 'get');
r.setStringParameter('tiers', '1,2,3');
var response = r.execute();


Hope this helps!


Thanks for your Response.

I have created RESTMessage as same way which you have specified in the above comments.

My only concern is, i need to post xml data to REST endpoint(like https:/xxx/). In Post Method, i have created REST Message Function Parameter Definition((like test and value is ${test}) and changed the type as xml for REST Message Function Parameter(like test and value is 123456789Demo(Xml Value)).

Once i click on Test link which is available in Post function, the xml values is posted successfully in REST endpoint. But i tried on background by using the code as follow

var r= new RESTMessage('Demo','post');
r.setStringParameter('test',"123456789Demo"); // Xml value
var response=r.execute();

the above code is not working and value is not posted in the REST endpoint.

Please let me know what i am making mistake in the code..

Many Thanks




If you are using POST, then put the variables that you plan on substituting in the CONTENT field as that field allow for variable substitution and that is the data that will be posted to the endpoint. You content field (using the example of tiers) would be like the following:

{"tiers":"${tiers}"}


it is working as expected..

Thanks a lot ...