Widget Refresh

vidishaagarwal5
Tera Expert

How can I refresh widget data in the Service Portal when a record is created, updated, or deleted through the standard ServiceNow UI (backend)?

3 ACCEPTED SOLUTIONS

Ravi Gaurav
Giga Sage

Hi @vidishaagarwal5 

 

Record Watch is a tool that allows a widget developer to respond to table updates in real-time. For instance, by using Record Watch, the Simple List widget can listen for changes to its data table and if new records are added, removed, or updated, the widget can update itself in real-time.

View solution in original post

MoreOver you can use the sample script :

e.g.

function(spUtil, $scope)

{ /* widget controller */

var c = this;

spUtil.recordWatch($scope, "incident", "active=true", function(name, data) { console.log(name); //Returns information about the event that has occurred console.log(data); //Returns the data inserted or updated on the table }); }

View solution in original post

miftikhar20
Kilo Patron

Hi @vidishaagarwal5,

you can add recordWatch on client controller to refresh widget data on record change.

spUtil.recordWatch($scope, 'incident', "active=true", function(name) {
$scope.server.get().then(function(response) {
c.data = response.data; // map client data to the updated server data
        });
});

You can find detailed guidance on this topic in the following learning module:

 

If my response helped, please mark it as the accepted solution so others can benefit as well.

 

View solution in original post

4 REPLIES 4

Ankur Bawiskar
Tera Patron

@vidishaagarwal5 

which widget are you referring?

which portal page is this?

💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏

Ravi Gaurav
Giga Sage

Hi @vidishaagarwal5 

 

Record Watch is a tool that allows a widget developer to respond to table updates in real-time. For instance, by using Record Watch, the Simple List widget can listen for changes to its data table and if new records are added, removed, or updated, the widget can update itself in real-time.

MoreOver you can use the sample script :

e.g.

function(spUtil, $scope)

{ /* widget controller */

var c = this;

spUtil.recordWatch($scope, "incident", "active=true", function(name, data) { console.log(name); //Returns information about the event that has occurred console.log(data); //Returns the data inserted or updated on the table }); }

miftikhar20
Kilo Patron

Hi @vidishaagarwal5,

you can add recordWatch on client controller to refresh widget data on record change.

spUtil.recordWatch($scope, 'incident', "active=true", function(name) {
$scope.server.get().then(function(response) {
c.data = response.data; // map client data to the updated server data
        });
});

You can find detailed guidance on this topic in the following learning module:

 

If my response helped, please mark it as the accepted solution so others can benefit as well.