escalation button on service portal

Evan2
Kilo Guru

Hi All,

I have created a widget "Escalate" to trigger escalations through email. But as per requirement I have to make it visible if-

  • Incident is not updated since last 4 days
  • State is not cancelled(8), resolved(6) & closed(7).
  • It should be visible only to caller or opened by user.

I tried doing that and its working partially. It is visible now for every state and after just submitting the incident.

Please find below the script for widget i have tried and help me to fix this.

HTML

<div>
<!-- your widget template -->
<div class="panel b" ng-if="data.showWidget">
<div class="panel-heading bg-primary">Actions</div>
<div class="panel-body">
<button type="button" class="btn btn-primary btn-block" ng-click="c.openModalEscalate()" ng-if="data.showEsc">Escalate</button>
</div>
<script>

<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">Do you want to escalate?</h4>
</div>
<div class="panel-body wrapper-xl">
<form name="modalEscalate" ng-submit="c.uiAction('esc')">
<input class="btn btn-primary" type="Submit" />

<button class="btn btn-primary" ng-click="c.closeModal()">${Close}</button>

</form>
</div>
</div>

</script>
</div>
</div>

 

Server script

(function() {
/* populate the 'data' object */
/* e.g., data.table = $sp.getValue('table'); */
// Get table & sys_id
data.table = input.table || $sp.getParameter("table");
data.sys_id = input.sys_id || $sp.getParameter("sys_id");

// Valid GlideRecord
var gr = new GlideRecord(data.table);
if (!gr.isValid())
return;

// Valid sys_id
//
if (!gr.get(data.sys_id))
return;

//Button Visibility
if(data.table == 'incident'|| data.table == 'sc_request'||data.table == 'sc_req_item' ||data.table == 'sc_task' && gr.active == true && (gr.caller_id == gs.getUserID() || gr.opened_by == gs.getUserID()) && gr.state != '6' || gr.state != '7' ||gr.state!= '8' ){
data.showWidget = true;
data.showEsc = true;

}
else {
data.showWidget = false;
data.showEsc = false;
}

//input
if (input && input.action) {
var action = input.action;

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

if (action == 'esc') {
// gs.addInfoMessage("Incident Escalated-1");
gr.setValue('u_incident_esc', 'true');
gr.comments = "Ticket Escalated";
// gs.addInfoMessage("Incident Escalated-2");
gr.update();
//gs.addInfoMessage("Incident Escalated-3");
gs.eventQueue('incidentEscalation', gr, gr.assigned_to.manager);
gs.addInfoMessage("Incident Escalated");
}
}
}

})();

 

 

Client controller

api.controller=function($uibModal, $scope, spUtil) {
/* widget controller */
var c = this;



// c.openModalEscalate = function() {
// c.data.action = "esc";
// c.server.update().then(function() {
// c.data.action = undefined;
// })

// }

c.uiAction = function(action) {
c.data.action = action;
c.server.update().then(function() {
c.data.action = undefined;
});
c.modalInstance.close();
};
c.openModalEscalate = function() {
c.modalInstance = $uibModal.open({
templateUrl: 'modalEscalate',
scope: $scope
});
};
c.closeModal = function() {
c.modalInstance.close();
};

};

 

 

image

 

Please help me to apply all the above visibility conditions.

Regards,

Kumar nandan

4 REPLIES 4

Shane41
ServiceNow Employee
ServiceNow Employee

Hi Evan,

Have you tried adding extra brackets to your if condition for button visibility

Something like this:

if((data.table == 'incident'|| data.table == 'sc_request'||data.table == 'sc_req_item' ||data.table == 'sc_task') && gr.active == true && (gr.caller_id == gs.getUserID() || gr.opened_by == gs.getUserID()) && (gr.state != '6' || gr.state != '7' ||gr.state!= '8' ))

Hope this helps,

Shane

Hi Shane ,

 

This is not working. Still the button is visible for every state.

 

Regards,

Kumar Nandan

Shane41
ServiceNow Employee
ServiceNow Employee

Hi Kumar,

I think it should be AND statements for the states not OR

Try this

if((data.table == 'incident'|| data.table == 'sc_request'||data.table == 'sc_req_item' ||data.table == 'sc_task') && gr.active == true && (gr.caller_id == gs.getUserID() || gr.opened_by == gs.getUserID()) && (gr.state != '6' && gr.state != '7' &&gr.state!= '8' ))

Kind Regards,

Shane

Thank you shane It worked for state validation.

Can you please help me to fulfill other additional  condition that it should be visible only if record is not updated since last 4 days.

 

Regards,

Kumar Nandan