- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2021 03:52 AM
We have created a REST API method by adding query parameter in it
I have ran the script by modified the Order number to other value in back ground script but still getting the same response.
Basically we are entering order number in one of our custom fields. based on this value we need to retrieve values from end point.
Please suggest how i can send order number dynamically in the rest script. Below is my script
try {
var r = new sn_ws.RESTMessageV2('Fixit_JDE', 'Order_Number');
r.setStringParameterNoEscape('order_number', '833129');
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
gs.print(responseBody);
}
catch(ex) {
var message = ex.message;
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2021 04:32 AM
You need to use variable substitution.
Follow the steps in Rest Message:
1) Set ${order_number} in query parameter value
2) Click Auto Generate Variables related link
3) Make sure Variable is added in Variable Substitution automatically
Once the above is done your script will substitute dynamic value for order_number. You can click Preview Script Usage, this variable substitution is added in generated code. Refer the screen below
Palani

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2021 04:07 AM
Use new variable (i'll name it myOrder) and pass it :
var myOrder = current.your_field_name_here (or use current.getValue())
the r.setStringParameterNoEscape('order_number', myOrder );
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2021 04:24 AM
Hi,
As mentioned you need to use variable substitution
please check this link
Variable substitution in outbound REST messages
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
09-12-2022 06:20 AM
Dear Ankur,
Can you please help me with a similar requirement?
The details are posted on the below link.
https://community.servicenow.com/community?id=community_question&sys_id=d89abdcb1bfdd1d8b3b911f8b04bcb98
Thanks,
Rijeesh Rathnakumar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2021 04:32 AM
You need to use variable substitution.
Follow the steps in Rest Message:
1) Set ${order_number} in query parameter value
2) Click Auto Generate Variables related link
3) Make sure Variable is added in Variable Substitution automatically
Once the above is done your script will substitute dynamic value for order_number. You can click Preview Script Usage, this variable substitution is added in generated code. Refer the screen below
Palani