Service Portal: Dynamically load data in the widget.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2025 02:39 PM - edited 02-14-2025 03:15 PM
Hello Community,
In my Widget Server script, when user clicks on "onDemand Preflight check" button I trigger a workflow that typically takes around 6 minutes to complete.
Q: How can I dynamically load new content when the status of the workflow changes to "completed"?
Q: Is using recordWatch() the correct approach to implement this functionality, or are there any better alternatives? If I apply recordWatch() on a table with a filter condition (such as looking for a specific state), it will monitor all records in that table. How can I target a specific record, for example, by sys_id?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-15-2025 10:05 AM
Hi,
the filter you pass into recordWatch can be a filter for a specific record. You'd use the sys_id to monitor a single record. With the process being 6 minutes, are your users going to wait that long? Or is it best to fire a notification for them to then return and view the result?
spUtil.recordWatch($scope,"incident","sys_id=<sys_id_goes_here>",function(name){
})
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2025 11:11 AM - edited 02-18-2025 11:25 AM
Hello @Kieran Anson I will definitely send a notification to prompt the user to return and view the result. Upon their return, if the workflow is still running, I want to load the results dynamically.
Could you help me understand how to invoke server-side code from a record watch? How can I retrieve the latest server-side results?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2025 04:05 AM
recordwatcher receives an update whenever the record is modified. I assume you're wanting to watch a record until a certain state occurs? You could wait for that record to be updated an then fire a function call within your record watcher script
Psuedo code example:
spUtil.recordWatch($scope,"incident","sys_id=<sys_id_goes_here>",function(name){
if(event.data && event.data.changes.includes('state')){
$scope.server.get({
'action' : 'doSomething'
}).then(function(response){
//do something
})
}
})
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2025 12:26 PM
@Kieran Anson In my widget, when the user clicks the "OnDemand Preflight" button, I trigger a backend workflow and pass the workflow's sys ID to my client controller (line 24). After receiving the sys ID, I use recordWatch
to monitor the state until it finishes. Once the state is completed, I intend to load the latest data from the server into the widget.
However, the issue I'm encountering is that I'm unable to see any console.log
statements inside the recordWatch
.