Refresh Page in Portal after ng-click

cnharris1
Kilo Sage

Good morning developers,

I have a service portal question. On the Ticket Conversations Page, I created two buttons that allows users to close their ticket if they accept the resolution or reopen the ticket if they reject the resolution. The buttons work fine but the problem is that I want to refresh the page after the user clicks either one of the buttons. How would I go about accomplishing that? Here's a copy of my code if that will help:

HTML:

<div class="panel panel-default" ng-if="data.showWidget">
 <div class="panel-heading">Actions</div>
 <div class="panel-body">
 <button type="button" class="btn btn-primary btn-block" ng-click="c.uiAction('accept')" ng-if="data.showResolve">Accept Resolution</button>
 <button type="button" class="btn btn-default btn-block" ng-click="c.uiAction('reject')" ng-if="data.showResolve">Reject Resolution</button>
 </div>
</div>

Client Script:

function($scope,spUtil,$location) {
var c = this;
c.uiAction = function(action) {
if(action == 'reject'){
var r = confirm("Are you sure you want to reject this request?");
if(r == false){
return;
}
}
c.data.action = action;
c.server.update().then(function() {
c.data.action = undefined;
})
}
}

 

Server Script:

(function() {
 
 // Get table & sys_id
 data.table = input.table || $sp.getParameter("table");
 data.sys_id = input.sys_id || $sp.getParameter("sys_id");
 
 // Valid GlideRecord
 gr = new GlideRecord(data.table);
 if (!gr.isValid())
 return;
 
 // Valid sys_id
 if (!gr.get(data.sys_id))
 return;

    //Button Visibility
  if(data.table == 'u_incident' && gr.incident_state == 3 && gr.priority > 2 || data.table == 'u_request' && gr.incident_state == 3 && gr.priority > 2){
    data.showWidget = true;
    data.showResolve = true;
  }
  else {
    data.showWidget = false;
    data.showResolve = false;
  }

 if (input && input.action) {
 var action = input.action;
 
 // If Incident table
 if (data.table == 'u_incident'|| data.table =='u_request') {
 if (action == 'accept') {
 // Close Incident
 gr.setValue('incident_state', 4);
 gr.setValue('u_resolved_date', gs.nowDateTime());
 gr.setValue('u_agreed_etr', false);
 gr.work_notes = "closed by caller";
 gr.comments = "User Closed Ticket";
 gr.setValue('u_closure_source', "ESS");
 gr.update();

  gs.addInfoMessage("Ticket " + gr.number + " has been closed!");
 }
 if (action == 'reject') {
 // Reopen Ticket
     gr.setValue('true')
     gr.setValue('incident_state', 5);
     gr.setValue('u_resolved_date', '');
     gr.u_reopen_count +=1;
     gr.update();
     gs.addInfoMessage("Ticket " + gr.number + " has been reopened!");
 }
 }
 }
 
})();

 

Thanks in advance,

 

cnharris

1 ACCEPTED SOLUTION

Prasant Kumar 1
Kilo Sage

Hi,

Please follow the below link:-

https://community.servicenow.com/community?id=community_question&sys_id=6536bef3db5caf88e0e80b55ca96...

 

If i was able to solve your query, please mark my answer correct and helpful.

Thanks & Regards

Prasant kumar sahu

View solution in original post

3 REPLIES 3

Prasant Kumar 1
Kilo Sage

Hi,

Please follow the below link:-

https://community.servicenow.com/community?id=community_question&sys_id=6536bef3db5caf88e0e80b55ca96...

 

If i was able to solve your query, please mark my answer correct and helpful.

Thanks & Regards

Prasant kumar sahu

Thanks Prasant, that pointed me in the right direction.

Haustin Kimbrou
Tera Contributor

Not sure if this helps anyone else, but the to the original question's point of redirecting. I just added "$window.location.href='myhref'" to the .then() of my c.server.update() call.

Also, for my purpose, I received the href from the server side code so I used that as my href.

HaustinKimbrou_0-1678680255877.png