Pass variable as argument to setStringParameterNoEscape('name', 'value' );
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-25-2019 07:38 AM
Trying unsuccessfully to pass a populated variable instead of a string.
This works
r.setStringParameterNoEscape('engine', '192.168.5.5:1671' );
This does not
var target = "192.168.5.5:1671"
r.setStringParameterNoEscape('engine', target );

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-25-2019 05:32 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-25-2019 09:02 PM
Hi Marc,
what value it sets?
Did you try to print the json request body being sent out?
Have you created variable substitution for that under the rest message function?
Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2019 05:28 AM
Using the variable name 'targetIP' does not work. Wrapping it in JSON does not work. Stringify does not work. Escaping it and not escaping it makes no difference - it doesn't work. It seems to only accept plain text enclosed in single quotes. Period.
I am not calling it from a form or Client script so there is no current.targetIP. The call is being made in a Script Include javascript.
I am able to test with the System Webservices REST Test feature passing 192.168.5.5:1671 as a Variable Substitution successfully.
This works -
targetIP = "192.168.5.5:1671"
try {
var r = new sn_ws.RESTMessageV2('x_nexsa_cmdb_pop.NXT Get all Device Scores', 'GetAllScores');
r.setMIDServer('marcmidserver');
r.setEccParameter('skip_sensor', true);
r.setStringParameterNoEscape('engine', '192.168.5.5:1671'); // Replace second argument with targetIP
r.setStringParameterNoEscape('device', 'CHIA428');
r.setStringParameterNoEscape('DESquery', '%29%20%28fro0device%20%28where%20device%20%28eq%20');
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
}
catch(ex) {
var message = ex.message;
} finally {
requestBody = r ? r.getRequestBody():null;
}
What is the syntax to get targetIP into the second argument ??

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2019 08:46 AM
Marc,
You have the correct syntax for passing a dynamically set variable as the second argument. My suggestion is you should enable HTTP logging for the outbound REST you are calling 'GetAllScores'.
1. Open the HTTP Method record for 'GetAllScores'
2. Under related links click 'Set HTTP Log level'
3. In the popup choose 'All'
Now try executing your rest message with the variable substitution like so:
targetIP = "192.168.5.5:1671"
try {
var r = new sn_ws.RESTMessageV2('x_nexsa_cmdb_pop.NXT Get all Device Scores', 'GetAllScores');
r.setMIDServer('marcmidserver');
r.setEccParameter('skip_sensor', true);
r.setStringParameterNoEscape('engine', targetIP );
r.setStringParameterNoEscape('device', 'CHIA428');
r.setStringParameterNoEscape('DESquery', '%29%20%28fro0device%20%28where%20device%20%28eq%20');
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
}
catch(ex) {
var message = ex.message;
} finally {
requestBody = r ? r.getRequestBody():null;
}
After you can navigate to 'Outbound HTTP Requests' under System Logs and view the details of your outbound request (request & Response).
Hopefully that will help you determine what error is occurring.