- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-26-2022 04:01 AM
Hello,
Just to say this is my first time trying to use/configure a REST message and have no previous knowledge at all !!!!
I am struggling with a REST message using a variable from a catalog request.
I have created a REST Message with an Endpoint that ends in 'request/servicenow/${username}'
The content is
<servicenow>
<username>${username}</username>
</servicenow>
The variable substitution is username No Escaping
The preview Script is as follows:
try { var r = new sn_ws.RESTMessageV2('Test Steve', 'Test POST'); r.setStringParameterNoEscape('username', ''); //override authentication profile //authentication type ='basic'/ 'oauth2' //r.setAuthenticationProfile(authentication type, profile name); //set a MID server name if one wants to run the message on MID //r.setMIDServer('MY_MID_SERVER'); //if the message is configured to communicate through ECC queue, either //by setting a MID server or calling executeAsync, one needs to set skip_sensor //to true. Otherwise, one may get an intermittent error that the response body is null //r.setEccParameter('skip_sensor', true); var response = r.execute(); var responseBody = response.getBody(); var httpStatus = response.getStatusCode(); } catch(ex) { var message = ex.message; }
If I run a Test from the message then something is received <servicenow> <username></username> </servicenow>
If I manually add a username then this also passed through ok.
I have a catalog item to gather the user name with a variable name of 'username'
There is a workflow with a run script as follows:
try {
var r = new sn_ws.RESTMessageV2('Test Steve', 'Test POST');
r.setStringParameterNoEscape('username', '');
//override authentication profile
//authentication type ='basic'/ 'oauth2'
//r.setAuthenticationProfile(authentication type, profile name);
//set a MID server name if one wants to run the message on MID
r.setMIDServer('XXXXXXXX-DEV');
//if the message is configured to communicate through ECC queue, either
//by setting a MID server or calling executeAsync, one needs to set skip_sensor
//to true. Otherwise, one may get an intermittent error that the response body is null
r.setEccParameter('skip_sensor', true);
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
}
catch(ex) {
var message = ex.message;
}
There are no errors but the endpoint only receives '<servicenow> <username></username> </servicenow>'
The username is not being embedded in the message as required.
Can anyone please help??
Thanks
Steve
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-26-2022 04:09 AM
Hi,
you are not setting the value in username variable if you are using variable substitution
try {
var r = new sn_ws.RESTMessageV2('Test Steve', 'Test POST');
r.setStringParameterNoEscape('username', <set some value here>);
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
}
catch(ex) {
var message = ex.message;
}
Regards
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
‎04-26-2022 04:09 AM
Hi,
you are not setting the value in username variable if you are using variable substitution
try {
var r = new sn_ws.RESTMessageV2('Test Steve', 'Test POST');
r.setStringParameterNoEscape('username', <set some value here>);
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
}
catch(ex) {
var message = ex.message;
}
Regards
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
‎04-26-2022 05:30 AM
Thanks for this,
I added r.setStringParameterNoEscape('username', current.variable_pool.username);
and it works great.
Regards
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-29-2022 07:30 AM
Hello again,
Thanks for your assistance with this and by adding the following line it does indeed send the entered username:
r.setStringParameterNoEscape('username', current.variable_pool.username);
This works great if the username is first.last
But nothing is sent if the username is entered as first last.
If you separate the names by a space then nothing is sent out by the script.
Are you able to advise why this may be?
Thanks
Steve