How to pass Query parameter dynamically in REST API method

praveen47
Tera Contributor

We have created a REST API method by adding query parameter in it

 

find_real_file.png

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;
}

1 ACCEPTED SOLUTION

palanikumar
Mega Sage

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

find_real_file.png

Thank you,
Palani

View solution in original post

4 REPLIES 4

Community Alums
Not applicable

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 );

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

As mentioned you need to use variable substitution

please check this link

Variable substitution in outbound REST messages

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

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

palanikumar
Mega Sage

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

find_real_file.png

Thank you,
Palani