- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-10-2017 10:42 AM
I have a requirement that is
Need to send variables that are submitted by user on a form using REST API. I created and tested the api it is working fine. But, I am trying to send the variables through workflow by calling rest message. But, when I send them it is giving "unable to parse the request details" then I got to know that I am not sending the variables in the required format. I don't know how to send variables in this format.
Can you please help me out how to send them using BR. I am using run script in workflow now some thing like
r.setStringParameterNoEscape('requestName',current.variables.Username);
Here is the format
{
"var1": "test1",
"var2": "Test2",
"var3": "test3",
"var4": "test4",
"var5": "test5",
"var6": "test6",
}
Let me know how should we write???
Solved! Go to Solution.
- Labels:
-
Integrations
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-10-2017 02:22 PM
This is how I ma doing an it works fine. Make sure to use .toString() while passing the value to JSON.
You can use below script which is much better way to conver to Json and stringify it
var jsonObj = {};
jsonObj.u_name = current.name.toString();
jsonObj.u_application_id = current.u_application_id.toString();
jsonObj.u_approval_group = current.change_control.toString();
jsonObj.u_category = current.category.toString();
jsonObj.u_assignment_group = current.assignment_group.toString();
try {
var r = new sn_ws.RESTMessageV2('CMDB Application Integration', 'POST');
r.setStringParameterNoEscape('content',global.JSON.stringify(jsonObj));
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
}
catch(ex) {
var message = ex.getMessage();
}
Also activate HTTP log and check your Request body if it is sent correctly.
Please mark this response as correct or helpful if it assisted you with your question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-10-2017 11:28 AM
Hello Rk,
Sample script
var sm = new sn_ws.RESTMessageV2("Update user","post");
var obj = {'var1' : 'test1', 'var2' : 'test2', 'var3' : 'test3'};
sm.setRequestBody(JSON.stringify(obj)); //setRequestBody(body string);The request body to be send in string format.
Reference:
https://developer.servicenow.com/app.do#!/api_doc?v=jakarta&id=r_RMV2-RESTMessageV2
https://developer.servicenow.com/app.do#!/api_doc?v=jakarta&id=r_RMV2-setRequestBody_String_body
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-10-2017 12:07 PM
How can I send current values???

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-10-2017 12:09 PM
var obj = {'var1' : current.getValue('PASS FIELD COLUMN NAME'), 'var2' : 'test2', 'var3' : 'test3'};
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-10-2017 01:59 PM
This is what I am trying bu tit is still not working, I don't know where am i making mistake
try {
var sm = new sn_ws.RESTMessageV2('Test', 'POST');
var obj = {'var1' : 'current.getValue('field1'), 'var2' : 'current.getValue('field2')};
sm.setRequestBody(JSON.stringify(obj)); //
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
gs.log("Successful" + responseBody +" status "+httpStatus);
}
catch(ex) {
var message = ex.getMessage();
}
}