- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-01-2023 04:37 PM
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-01-2023 07:09 PM - edited 01-01-2023 07:10 PM
@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;
Please mark as correct answer if this solves your issue.
ServiceNow Community Rising Star, Class of 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-01-2023 07:09 PM - edited 01-01-2023 07:10 PM
@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;
Please mark as correct answer if this solves your issue.
ServiceNow Community Rising Star, Class of 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-01-2023 07:43 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-01-2023 07:47 PM
@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
ServiceNow Community Rising Star, Class of 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2025 06:33 AM
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?