- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2020 02:48 AM
in reference to link: https://community.servicenow.com/community?id=community_question&sys_id=5ab3cd28dbafc4d0feb1a851ca96...
please refer as am stuck with:
How are you determining whether the rest call is working fine or not? it works when i just trigger the script
Are you not getting desired response by sending those variable values?no ,because for two reasons:
case 1 : when you fetch the field value you use syntax:
r.setStringParameterNoEscape('var1', current.sys_id);
case 2: when you fetch values from the variables:
r.setStringParameterNoEscape('var1', current.variables.sys_id);
and in my case am not using any of the above method as you can see in my script that am trying to get values which i have fetched in that script only like i took the value of short description field in description field.
var description = current.short_description;
then i bifurcated that description field in two variables:
var variable1 = "test"
var variable2 = "test"
now i want to send the values of variable1 ,variable2 to my rest msg but how
really urgernt!!
Solved! Go to Solution.
- Labels:
-
Personal Developer Instance

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2020 04:53 AM
Hi,
As checked, the rest API has to be called from the mid server. Set the midserver in your rest api under http request and then for substitution, try setQueryParameter and check once.
Also, you can call the end point on the fly like this instead of creating the message.
var sm = new sn_ws.RESTMessageV2();
sm.setEndpoint("your_API_URL_with_args");
sm.setHttpMethod("get");
sm.execute();
Kindly mark the comment as a correct answer and helpful if it helps to solve your problem.
Regards,
Asif
2020 ServiceNow Community MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2020 07:10 AM
So basicly you saying when you provide a 'hardcoded' value it works, when you provide a variable it does not work.
then that points to the variable not being correct. Not knowing what the endpoint expects nor what you are sending makes it really hard to debug
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2020 07:21 AM
There are multiple steps you need to perform before writing business rule.
To test rest call you can open one of the method and click on "test" related link.
1) Have you set content and substitute variable in rest message method?
2) if you substitute variables then only you can use that variable in your script(variable name should be same to substitute variable)
3) once you substitute variable you can use below code
r.setStringParameter("substitue variable",variable1);
r.setStringParameter("substitue variable",variable2);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2020 04:53 AM
Hi,
As checked, the rest API has to be called from the mid server. Set the midserver in your rest api under http request and then for substitution, try setQueryParameter and check once.
Also, you can call the end point on the fly like this instead of creating the message.
var sm = new sn_ws.RESTMessageV2();
sm.setEndpoint("your_API_URL_with_args");
sm.setHttpMethod("get");
sm.execute();
Kindly mark the comment as a correct answer and helpful if it helps to solve your problem.
Regards,
Asif
2020 ServiceNow Community MVP