- 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 05:41 PM
@PeteM1 send the server side code as well. It depends on that.
ServiceNow Community Rising Star, Class of 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-01-2023 05:51 PM
Hello @jaheerhattiwale and thank you for the quick response. The server code is unchanged from the OOB widget. Below is the code I am currently using.
Thanks again.
(function(){
/* "use strict"; - linter issues */
// populate the 'data' object
var sp_page = $sp.getValue('sp_page');
var pageGR = new GlideRecord('sp_page');
pageGR.get(sp_page);
data.page_id = pageGR.getValue("id");
$sp.getValues(data);
if (data.field_list) {
data.fields_array = data.field_list.split(',');
} else {
data.field_list = $sp.getListColumns(data.table);
}
if (input) {
data.p = input.p;
data.o = input.o;
data.d = input.d;
data.q = input.q;
}
data.p = data.p || 1;
data.o = data.o || $sp.getValue('order_by');
data.d = data.d || $sp.getValue('order_direction');
data.page_index = (data.p - 1);
data.window_size = $sp.getValue('maximum_entries') || 10;
data.window_start = (data.page_index * data.window_size);
data.window_end = (((data.page_index + 1) * data.window_size));
data.filter = $sp.getValue("filter");
var gr = new GlideRecordSecure(data.table);
if (!gr.isValid()) {
data.invalid_table = true;
data.table_label = data.table;
return;
}
data.table_label = gr.getLabel();
options.table = data.table;
options.fields = data.field_list;
options.o=data.o;
options.d= data.d;
options.filter=data.filter;
options.window_size=data.window_size;
options.view = data.view;
options.useInstanceTitle = true; // to make sure Data Table widget uses headerTitle always
options.headerTitle = options.title;
options.show_breadcrumbs=true;
data.dataTableWidget = $sp.getWidget('widget-data-table', options);
})();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-01-2023 06:20 PM
@PeteM1 let me check this on my PDI and come back here
ServiceNow Community Rising Star, Class of 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-01-2023 06:33 PM
Hey @jaheerhattiwale - again...thank you.
Just wanted to add the steps I took…
1) cloned the widget mentioned above.
2) added the cloned widget to a new page I created
3) specified the table, fields, etc.
4) tested (and this is where the records disappeared)