Dynamic Service Portal Buttons to Change State not Refreshing

ryanwoodburn
Kilo Expert

Hi

I have created a custom widget containing 3 buttons that are used to set the state of an Incident.


Their display is dynamic, and certain states will not show certain buttons.   This is done in the html using ng-if="data.state!=130 && data.state!=3", for example.

When I click these buttons, they change the state, add a relevant comment, and a splash header is displayed.   This is all working, and you can see the update on the form without refreshing.

However, the old button will still display and the new one not appear, until I manually refresh the browser window.

E.g. If I select Pass Back to change from awaiting client to Work in Progress, the Pass Back button will not disappear and the Resolve button will not appear until I refresh the browser.

I have attached my code below.

Any help appreciated

Thanks

HTML

<div ng-if="data.state!=3 && data.closeCode!=60">

  <div>

  <div class="panel-heading bg-primary"> <b>Available Actions</b></div>

</div>

<div class="panel panel-default" >

<div class="panel-body">

<button ng-if="data.state!=130 && data.state!=3" type="button" class="btn btn-primary3" display= inline-block ng-click="c.uiAction('Resolve')">Resolve</button>

<button ng-if="data.state==110" type="button" class="btn btn-primary2"   ng-click="c.uiAction('Pass back')">Pass Back</button>

<button ng-if="data.state==130 && data.closeCode!=60" type="button" class="btn btn-primary2"   ng-click="c.uiAction('Accept Solution')">Accept Solution</button>

</div>

</div>

  </div>

Client Script

function() {

  var c = this;

c.uiAction = function(action) {

if(!confirm(action + " - are you sure?")) 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;

gr.get(data.sys_id);

if (!gr.canRead())

return;

data.number = gr.getDisplayValue('number');

data.state = gr.getValue('state');

data.closeCode = gr.getValue('close_code')

// Valid sys_id

if (!gr.get(data.sys_id))

return;

if (input && input.action) {

var action = input.action;

// If Incident table

if (data.table == 'incident') {

if (action == 'Pass back') {

// Resolve Incident

gr.setValue('state', 2);

gr.update();

//action.setRedirectURL(current);

gs.addInfoMessage(data.number + ' returned to action. Thank you');

}

if (action == 'Resolve') {

gr.setValue('state', 130);

gr.setValue('close_notes', 'Resolved by ' + gs.getUserDisplayName());

gr.setValue('close_code', 60);

//gr.setvalue('active', false);

gr.setDisplayValue('comments', 'This has been set to Resolved by ' + gs.getUserDisplayName() + '. \nIf the issue still persists, please add an update and we will reopen to investigate.\nIf no update is added this incident will close in 10 days.\n\nThank you for your help in resolving this.' );

gr.update();

//action.setRedirectURL(current);

gs.addInfoMessage(data.number + ' has been resolved.   Thank you for your help');

}

if (action == 'Accept Solution') {

// Closes Issue Incident

gr.setValue('state', 3);

gr.setValue('u_cust_agree', 'closure');

gr.comments = 'This solution has been accepted by ' + gs.getUserDisplayName() + ' .\n\nThe Incident has now been closed.\n\nThank you';

//gr.setDisplayValue('comments', 'This solution has been accepted by ' + gs.getUserDisplayName() + ' .\n\nThe Incident has now been closed.\n\nThank you')

gr.update();

//action.setRedirectURL(current);

gs.addInfoMessage('Thank you for accepting our solution for ' + data.number);

/*

//if(confirm("Are you sure you want to Close this Incident?")){

//Close incident

gr.setValue('state', 3);

gr.setValue('u_cust_agree', 'closure');

gr.setValue('close_notes', 'Closed by ' + gs.getUserDisplayName());

gr.setValue('close_code', 60);

gr.setvalue('active', false)

gr.update();

action.setRedirectURL(current);

gs.addInfoMessage(data.number + ' has been closed');

*/

}

}

}

//}

})();

1 ACCEPTED SOLUTION

Can you put this line at the end of the server script as well, after all the action scripts and try again.



data.state = gr.getValue('state');



Please mark this response as correct or helpful if it assisted you with your question.

View solution in original post

6 REPLIES 6

Below thread could be helpful for the 2nd point



Add automated comments/updates as Admin user instead of last user



Please mark this response as correct or helpful if it assisted you with your question.

Hi, i tried adding the code to the end of the server action script but it doesn't seem to do anything. Can you advise or share how the code looks like that actually does the refresh upon button update ?