- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2022 08:07 AM
I am new with servicenow and I'm trying to do what I describe below.
I have this service catalog:
And I have an outbound rest message that sends the following parameters in the content:
{
"templateParameters": {
"environment": "test",
"team": "test",
"vm_type": "linux" ,
"vm_number": "1",
"vm_size": "large",
"data_diks_additional": "No",
"vm_password": "test",
"data_diks_adittional_number": "0",
}
}
But what I need to do - and I have no idea how to do it - is to get the variables from the service catalog and put them in the content of the parameters. I think I can do it in the workflow; I read in the documentation that I can do something like
In the request:
"environment": ${environment}
In the workflow script:
var environment = current.variables.environment;
Any suggestion about how to do it?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2022 08:58 AM
Hi,
I think the below script can give you an idea of how you can map variable values to the JSON context.
// you can do this in run script in workflow or from where ever you are executing the REST API
// current is the current context of RITM record
var context = {
templateParameters: {
environment: current.variables.environment.toString(),
team: current.variables.team.toString(),
vm_type: current.variables.vm_type.toString(),
vm_number: current.variables.vm_number.toString(),
vm_size: current.variables.vm_size.toString(),
data_diks_additional: current.variables.data_disk_additional.toString(),
vm_password: current.variables.vm_password.toString(),
data_diks_adittional_number: current.variables.data_disk_add_num.toString(),
},
};
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Sagar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2022 08:24 AM
You need to use REST API methods to pass variables from your catalog item to a REST API.
Take a look into below
https://developer.servicenow.com/dev.do#!/reference/api/rome/server/c_RESTMessageV2API
Regards,
Sachin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2022 08:38 AM
Hi,
yes you can use workflow run script and use REST Message in script
For those variables you can use variable substitution
OR
you can also use REST Activity in workflow
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
03-01-2022 08:58 AM
Hi,
I think the below script can give you an idea of how you can map variable values to the JSON context.
// you can do this in run script in workflow or from where ever you are executing the REST API
// current is the current context of RITM record
var context = {
templateParameters: {
environment: current.variables.environment.toString(),
team: current.variables.team.toString(),
vm_type: current.variables.vm_type.toString(),
vm_number: current.variables.vm_number.toString(),
vm_size: current.variables.vm_size.toString(),
data_diks_additional: current.variables.data_disk_additional.toString(),
vm_password: current.variables.vm_password.toString(),
data_diks_adittional_number: current.variables.data_disk_add_num.toString(),
},
};
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Sagar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2022 07:55 AM
I had tried something like that, but wasn't lucky. So, what I did now was to set a variable in the HTTP content and I overwrite that variable in an script, but I get the error message "Cannot convert null to an object", here is the code:
var reqBody = {
templateParameters: {
environment: current.variables.environment,
team: current.variables.team,
vm_type: current.variables.vm_type,
vm_number: current.variables.vm_number,
vm_size: current.variables.vm_size,
data_diks_additional: current.variables.data_disk_additional,
data_diks_adittional_number: current.variables.data_disk_add_num
},
};
try {
var sReqBodyData = JSON.stringify(reqBody);
var r = new sn_ws.RESTMessageV2('Dummy REST API', 'POST');
r.setStringParameterNoEscape('messageBody', sReqBodyData);
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
gs.print(JSON.parse(responseBody));
} catch (ex) {
var message = ex.message;
gs.print(message);
}