Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to prevent users resolving their own tickets for one specific service

Andrew Eyre
Tera Contributor

On the Service Portal, users have the Actions menu, from which they can self-resolve any ticket that has them set as the caller. 

We want to hide this option for one specific service, but I can't work out how to do it. 

I have had a look in the Widget - Standard Ticket Actions and I can see that this code controls the visibility of the options

    if (incidentGr.get(incidentSysId)) {
var incidentUtils = new global.IncidentUtils();
data.canResolve = incidentUtils.canResolveIncident(incidentGr);
data.canReopen = incidentUtils.canReopenIncident(incidentGr);
data.canClose = incidentUtils.canCloseIncident(incidentGr);
data.showActions = data.canResolve || data.canReopen || data.canClose;
    }
 
So I was thinking the easiest way would be to check if the ticket service matched the one I want to lock out and set data.canResolve to false, but I am open to any suggestions
2 REPLIES 2

Bert_c1
Kilo Patron

Hi Andrew,

 

You can add a new function to the 'incidentUtils' script include, with name similar to 'canResolveIncident' found in 'incidentUtilsSNC' script include.  and then call the new function in your script above.

I was actually a step ahead of you there, it was the incidentUtils script I tried modifying first.. 

I added this to incidentUtils

IncidentUtils.canResolveIncidentNew = function(current) {
        if (current.incident_state == IncidentState.CLOSED || current.incident_state == IncidentState.RESOLVED || current.incident_state == IncidentState.CANCELED)
            return false;
if (current.business_service == "d2d01770c32c915008987155df013102")
return false;
        if (gs.hasRole("itil_admin,itil,sn_incident_write"))
            return true;
        if (current.caller_id == gs.getUserID())
            return !this._isMajorIncident(current);
        return false;
    };
 
I then called that from the widget script by modifying the data.CanResolve line :

data.canResolve = incidentUtils.canResolveIncidentNew(incidentGr);
 
It didn't like it. 
it threw the error 
"Server Javascript error Method "toString" called on incompatible object"

 
so clearly I have a syntax issue somewhere