- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2023 05:30 AM
Hello community,
I try to call an external API with a defined JSON in case an incident is created.
I saw this video:
#4 Rest Outbound Integration in ServiceNow| Rest Message |Create an Incident in third party tool (https://www.youtube.com/watch?v=YE7jcl-5whs)
this is my code: in the business rule:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var request = new sn_ws.RESTMessageV2('RESTTEST','RESTTESTPOST');
//request.setStringParameterNoEscape('u_caller',current.caller_id);
//request.setStringParameterNoEscape('u_short_description',current.short_description);
request.setStringParameterNoEscape('u_sd',current.short_description);
var response = request.execute();
var responseBody = response.getBody();
var statuscode = response.getStatusCode();
var errorMsg = response.getErrorMessage();
gs.info("responseBody"+responseBody);
})(current, previous);
The trigger works fine, the external API is called, but i just see
in the text field I want to transmit not the data stored in "current.short_description" in my variable to be replaced (u_sd)
REST Message:
"text" : "$(u_sd)".
So i would need the value stored in "current.short_description" be transmitted in the REST call and NOT like at the moment the pure placeholder "$(u_sd)". Do I have to build the whole final string to be sent in the business rule code?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2023 03:35 AM
Did you create a variable substitution for your placeholder?
If not then it won't work
Variable substitution in outbound REST messages
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2023 05:46 AM
it should replace the value in the placeholder
what it is sending currently?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2023 06:21 AM
@Ankur Bawiskar this for your reply.
Indeed it is just the pure placeholder that is transmitted in the message. But in contrast to the example in the video I referred to in my previous post my JSON structure is more nested. It is from an SMS API.
You see the relevant data field is the "text" field.
However, might there be some other setting to be changed such that in the string the $(...) is recognized as a placeholder?
Or should I put all the JSON Content into the JavaScript based Rule and try to hand over just the final version of the JSON to the content field in the HTTP Request. But of course I don't know how this would be done...
{
"options" : {
"src" : "SMSTest",
},
"messages" : [ {
"text" : "$(u_sd)",
"recipients" : [ {
"dst" : "+49176123456"
}]
}
]
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2023 03:26 AM
@Ankur Bawiskar : Any possibility on your side to reproduce this phenomenon that the "placeholder" is not replaced by the desired value in such a REST call? Having just the string with the placeholder transmitted is of course not a valid solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2023 03:35 AM
Did you create a variable substitution for your placeholder?
If not then it won't work
Variable substitution in outbound REST messages
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader