Refresh Portal Page after Save

Stanley Martin
Tera Guru

I know this question has been asked before, but I really haven't found anything that resembles a good answer, so I'll ask it again.
I have a Portal page using the Form widget.  I have a custom page that has this widget on it.  I have added my own widget below this one.  When I save the form, the record is saved, but my added widget won't update until I refresh the page.  Why doesn't it refresh when Save is clicked?
So how/where do I modify this so that a refresh is actually performed after a Save?

4 REPLIES 4

Saurav11
Kilo Patron
Kilo Patron

Hello,

 

Please check the below post:-

 

https://www.servicenow.com/community/developer-forum/service-portal-how-to-refresh-webpage-on-ng-cli...

 

Please mark my answer as correct based on Impact.

That didn't seem to work for what I was looking for.  However, I was able to find something that did work.

 

Thanks for responding.

ChrisBurks
Mega Sage

I know you said you found something that worked for you but in case others stumble upon this I thought I would give my two cents.
In this scenario since a form is being submitted a record on a table is being inserted/updated and maybe even deleted. In the custom widget the recordWatch method from the spUtil api can be used to "watch" when an action has been performed on a specific table. The method takes a callback function that gets fed the details of the action allowing you to then know when to refresh or perform other actions in the custom widget.

Example from the ServiceNow Docs: https://docs.servicenow.com/bundle/utah-api-reference/page/app-store/dev_portal/API_reference/spUtil...

//A simple recordWatch function.
spUtil.recordWatch($scope, "live_profile", "sys_id=" + liveProfileId);

//In a widget client script
function(spUtil, $scope) {
  /* widget controller */
  var c =this;

  // Registers a listener on the incident table with the filter active=true, 
  // meaning that whenever something changes on that table with that filter, 
  // the callback function is executed.    
  // The callback function takes a single parameter 'response', which contains 
  // the property 'data'. The 'data' property contains information about the changed record. 
  spUtil.recordWatch($scope, "incident", "active=true", function(response) {
        
    // Returns the data inserted or updated on the table 
    console.log(response.data);   
    
    });
}

 

Funny you should mention that, because that is exactly what I did.  I little bit different after that, but I used a record watch.