Constructing a REST message body using variable values from screen (form)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-09-2019 12:14 AM
I'm trying to send a POST request with recordless REST messagev2, that is very similar to the example script below -
var restMessage = new sn_ws.RESTMessageV2(); restMessage.setBasicAuth("abc", "efgh"); restMessage.setHttpMethod("post"); restMessage.setEndpoint("http://<instance>.service-now.com/api/now/table/incident"); restMessage.setRequestBody("{\"short_description\" : \"Test incident\"}"); var response = restMessage.execute();
On the UI screen, I have field 'Short Description' (Name= u_shortDescription).
How do I insert the value of the field 'Short Description' in my script, instead of the string \"Test incident\"?
I want the target to receive the value on the UI. (ie. current.u_shortDescription).
I tried using following syntax -
var sd = current.u_shortDescription;
restMessage.setRequestBody('{\"short_description\" : \"{{sd}}\" }');
OR
var sd = current.u_shortDescription;
restMessage.setRequestBody('{\"short_description\" : \"$(sd)\" }');
But none of the above works. The POST requests inserts a record on the target table, but the field 'short_description' is left blank.
Can someone please help with the correct syntax?
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-09-2019 11:27 PM
can you paste your business rule screenshot ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-09-2019 11:43 PM
If you haven't already checked you may also want to confirm the format the destination allows\accepts for each field; Not all integrations are built as well as SNC's and your target may not be consistant with the way it treats different fields.
I sometimes also find it easier visually to create an object then set it as the request body.
var myObject = { 'field_1' : true, 'field_2' : 'Some Text', 'field_3' : dotwalk.myValue };
myAction.setRequestBody(JSON.stringify(myObject));