Asynchronous REST Messages from UI Action?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-13-2018 08:22 PM
I'm currently working on an integration where a user will be able to trigger a Jenkins job from a UI Action on a record. Essentially, there is a UI Action, and when a user clicks it, in the script body of the UI Action it calls a script include and executes a few functions which trigger REST messages to a Jenkins server.
The core functionality works great. However, whenever the user clicks the button, the form hangs for a few seconds as it processes the REST messages and such from the script.
So, I want to explore executing the API calls asynchronously inside the UI Action script body instead of having the user wait for the return from the script include functions. Ideally, I would have an info message telling the user that the integration has been initiated and to check the work notes for results, all while the API calls are going on in the background.
Has anyone had experience with this, and if so, what's the best way to go about it? I know it's easy to schedule REST messages asynchronously with business rules, but what about inside a script body? I've researched and found different references to the following functions but could not find much documentation on it:
- ScheduleOnce()
-
SncTriggerSynchronizer.executeNow()
- scheduleScript()
Thanks in advance!
- Labels:
-
Integrations
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-13-2018 09:03 PM
1. If you are using this application on platform only and it not used on service portal then you could simply make that ui action as client (Client ui actions not supported by service portal). Call the rest message from a client callable script include and use glide ajax to call that script include asynchronously from ui action.
2. In case you are using the application from server side the you could use onSubmit client script for glide ajax call to script include. use g_form.getActionName() function to determine which ui action was clicked.
3. You could also think of script actions or async business rules.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-13-2018 09:13 PM
Another way you can do is - Build the work for the REST call and before call the REST call add Timer for 1 sec and call the REST call in the script activity. then initiate the workflow in UI Action.
By Adding wait activity in workflow it will create the timer and user will get the session back immediately.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-14-2018 04:31 PM
Great answers. I actually went the route of making this integration event-driven. From the UI Action I am creating an event, and then using a Script Action I am firing off the script that calls the REST messages.
The following community post answer is how I accomplished this: https://community.servicenow.com/community?id=community_question&sys_id=564d4fa9db9cdbc01dcaf3231f96...