- 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-03-2022 08:22 AM
try this
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', JSON.stringify(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);
}
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-06-2022 07:17 PM
Thank you for marking my response as helpful.
If my response helped please mark it correct and close the thread so that it benefits future readers.
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-09-2022 11:37 AM
I had more errors than just this, but it's worth to say that before using the variables in the json, they must be declared in the script just like this:
var environment = current.variables.environment.toString();
var team = current.variables.team.toString();
var vm_type = current.variables.vm_type.toString();
var vm_number = current.variables.vm_number.toString();
var vm_size = current.variables.vm_size.toString();
var data_diks_additional = current.variables.data_diks_additional.toString();
var data_diks_additional_number = current.variables.data_diks_additional_number.toString();
var reqBody = {
"templateParameters": {
"environment": environment,
"team": team,
"vm_type": vm_type,
"vm_number": vm_number,
"vm_size": vm_size,
"data_diks_additional": data_diks_additional,
"data_diks_additional_number": data_diks_additional_number
}
};
Truly thankful with all you for your help 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2023 07:54 AM