How to call OUTBOUND REST Message in an UI Action. FYI: This integration is inside a scoped application & authentication type is 'oauth2'.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2021 10:39 PM
How to call OUTBOUND REST POST Message in an UI Action.
FYI: This integration is inside a scoped application & authentication type is 'oauth2'.
Requirement: On create Button Click REST POST Message should trigger & after success values to be set in Form from response values.
I already tried using Preview Script Usage from REST POST Message in UI Action, but it's not working.
try { var r = new sn_ws.RESTMessageV2('Testxxxxxxxx', 'post');
r.setAuthenticationProfile('oauth2', profile name);
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
} catch(ex) {
var message = ex.message;
}
- Labels:
-
Integrations
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2021 10:41 PM
Hi
Yes, it is possible to call REST Message from a UI Action. Using client side UI action -> Check the client check-box on UI Action and use GlideAjax for rest API call. get the response from Rest service and return it back to UI action. After getting response In Client UI action You can set the value by use g_form.
Regards,
Gunjan
Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2021 09:37 PM
Hi
Thanks for your quick reply. I have tried doing ajax call from UI action(client check-box on UI Action checked) to call a script include(client callable) which contains REST API details. But it is not working.
So as you suggested, directly we can use GlideAjax for rest API call in UI action, can you please share some sample code to refer for REST OUTBOUND POST message with 'oauth2' setup.
FYI: Its inside a scoped application.
Thanks,
Suchi

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2021 11:37 PM
I would try a different approach here. Not sure where your REST endpoint is, but it might also be behind a Firewall requiring MID Server - if so doing a synchronous call to it with the user waiting is not a great UX.
The recommendation would be to create a subflow to embed your REST call in it and call this subflow via API. Ideally you call the flow asnychronously, but you also can do that synchronously if you need to. The API doc for it is here.
It will required IntegrationHub StartPack license - which is free of charge.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2021 09:19 PM
Hi
Thanks for your quick response & new idea. However i have few quick ask on this.
1) REST OUTBOUND call is inside a scoped application. Is this matter?
2) Authentication Type as mentioned "oauth2", which is token based. So how to do the same in this. Can you please share some sample code to embed REST OUTBOUND POST Method with the above authentication in place to make an asynchronous call.
3) The instance is in Orlando release.
Looking forward to your swift response.
Thanks,
Suchi