Recordwatch question..

PeteM1
Tera Contributor

Hello all.

 

I cloned a copy of the datatable from instance definition widget and added the following code for a record watcher:

 

spUtil.recordWatch($scope, "x_325383_modules_exm_module_table", "", function(name) {
console.info('this is a test');
spUtil.update($scope);
});

 

Other than that bit of code, the widget was unchanged. When I add a new record to the table then go back to view the results, all records are removed (the console.info is printed to the console). It's only when I do a browser refresh do I see them again. Is there another modification I need to make to the widget in order for the the records to update and remain?

 

Any thoughts would be appreciated.

1 ACCEPTED SOLUTION

@PeteM1 Tried and tested 100% working solution.

 

Replace the recordwatch function as below:

spUtil.recordWatch($scope, "x_325383_modules_exm_module_table", "", function(name) {
spUtil.get("widget-data-table", $scope.data.optionValues).then(function(response) {
$scope.data.dataTableWidget = response;
});
});

 

And add the below line in Server Script above "data.dataTableWidget" line as shown in image below:

data.optionValues = options;

 

jaheerhattiwale_0-1672628904128.png

 

 

Please mark as correct answer if this solves your issue.

 

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023

View solution in original post

8 REPLIES 8

@PeteM1 Tried and tested 100% working solution.

 

Replace the recordwatch function as below:

spUtil.recordWatch($scope, "x_325383_modules_exm_module_table", "", function(name) {
spUtil.get("widget-data-table", $scope.data.optionValues).then(function(response) {
$scope.data.dataTableWidget = response;
});
});

 

And add the below line in Server Script above "data.dataTableWidget" line as shown in image below:

data.optionValues = options;

 

jaheerhattiwale_0-1672628904128.png

 

 

Please mark as correct answer if this solves your issue.

 

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023

Hello @jaheerhattiwale and thank you very much. This change does indeed detect and 'refresh' when a new record is added. Is it possible to have it also detect when an update to an existing record is made? I am looking through the code you added trying to get a better understanding on how it worked. It does appear the code actually executes on an update, but the values in the table remain the same. 

@PeteM1 For update also the code works.

 

And for better understanding of the code and embedded widget please check out below link:

https://serviceportal.io/docs/documentation/widget_embedded.md

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023

I have the same issue as PeteM1, basically embedded widget calls DataTable widget which already has it's own watcher function (initRecordWatcher), and it should update table on update, your code gets the response, but I think that, let's call it "wrapper" (instance definition widget) is not re-rendering the table.
Any ideas why? May be because they are in the different application scopes? Or maybe something wrong with the updateRowFromRW which is used for update case?