Need help with record watch on single record
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-13-2017 05:14 AM
I am attempting to use the spUtil recordWatch on a widget that looks at a referenced record of the open record. On my service portal page, I looked over the Real Time To Do App using Service Portal & Record Watchers - ServicePortal.io - Service Portal, CMS,... video in attempt to replicate. I am not using the first portion as I am not adding any items to a table. I am simply looking at a record and need to see when it changes.
The widget that shows the data pulls a referenced record and is set a gr with different data variables set to their corresponding field on the record. As for my recordWatch portion in the client controller, I have :
function ($scope, spUtil,) {
var c = this;
spUtil.recordWatch($scope, "x_access_task", "sys_id=" + data.sys_id, function(name, data) {
spUtil.update($scope);
})
When the record is updated, whether that be the state, description, or any other field, nothing changes live. I'm sure I am probably over thinking this, but does anyone have any thoughts as to why it doesn't update?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-13-2017 02:02 PM
Hi Robert,
I'm not sure if you have solved your issue yet but from the code you posted I'm surprised that you're not getting an error on the page.
In line 3, I see that you're setting the "sys_id" with data.sys_id. The issue with this is that the data object like that is only available on the server script.
In order to use it in the Client Controller it needs to be used like this "c.data.sys_id" or "$scope.data.sys_id" (if c isn't set).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-13-2017 02:08 PM
I also see another issue. In defining the Client Controller function line 1, you have an extra comma in the parameters.
If you're using the "widget editor" it will allow you to save this error. In the regular Service Now interface it won't allow you to save the record with that trailing comma.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2017 03:54 AM
Thanks. I have gone through and fixed that. However, I still have no luck. I have even tried setting the sys_id= the current record's sys_id, and all tasks. I added a gs.log to ensure I was getting the correct sys_id when using c.data.sys_id and I am. None of the field values update though. Do they need to be modal? I'm kind of confused as to what that does and if it is needed. I am going to do some additional research on it now and see what I can find. Let me know if you have any additional input. Below is the updated code:
function ($scope, spUtil) {
var c = this;
spUtil.recordWatch($scope, "x_access_task" , "sys_id=" + c.data.sys_id, function(name, data) {
spUtil.update($scope);
})
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2017 05:14 AM
I've also added a console.log(data); and am able to see a record update entry. But the data on the widget doesn't update.