Hide 'Close Incident' button based on 'State' == Resolved

Pierre5
Kilo Expert

Dear Community,

I was wondering if someone could help with the following…

We need to hide the ‘Close Incident’ button (affect all users) when the ticket is in a ‘State’ of Resolved. It currently serves no purpose at present, and that confuses some people. incident.[incident]

I’m a novice, so any instructions or advice would need to be perfectly clear. Baby steps would be nice. 🙂

find_real_file.png

 

Your help will be much appreciated.

Kind regards,

 

Pierre

1 ACCEPTED SOLUTION

You will have to put that in the condition as well. 

 

(current.incident_state != '1' && current.incident_state != '7' && current.incident_state != '6') && (gs.hasRole("itil") || gs.hasRole("itil_admin") || current.caller_id == gs.getUserID() || gs.hasRole("admin"))

 

Hope you got the resolution with my help.

Can you mark correct answer to close this thread?

 

Regards,

Omkar Mone

View solution in original post

24 REPLIES 24

Hi,

try to put that in script include function and call that from the condition field

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi Ankur,

The 'Condition' field has a character limit. So I guess I would need to add this as a function in my existing script.

My Condition is too long because of the amount of roles.

(current.incident_state != '1' && current.incident_state != '7' && current.incident_state != '6') && (gs.hasRole("itil") || gs.hasRole("itil_admin") || gs.hasRole("admin") || gs.hasRole("assessment_admin") || gs.hasRole("certification") || gs.hasRole("cmdb_query_builder") || gs.hasRole("dependency_views") || gs.hasRole("sn_bm_client.benchmark_data_viewer") || gs.hasRole("template_editor") || gs.hasRole("view_changer")current.caller_id == gs.getUserID())

 

The current Script/functions are:

What would the condition look like as a function (function onLoad() {) in the below script please.

 ************************************

(function onLoad() {)

var current.incident_state != '1' && current.incident_state != '7' && current.incident_state != '6') && (gs.hasRole("itil") || gs.hasRole("itil_admin") || gs.hasRole("admin") || gs.hasRole("assessment_admin") || gs.hasRole("certification") || gs.hasRole("cmdb_query_builder") || gs.hasRole("dependency_views") || gs.hasRole("sn_bm_client.benchmark_data_viewer") || gs.hasRole("template_editor") || gs.hasRole("view_changer")current.caller_id == gs.getUserID()

//Would this work?

function resolveIncident(){
//Set the 'Incident state' and 'State' values to 'Resolved', and display mandatory fields
g_form.setValue('incident_state', 6);
g_form.setValue('state', 6);
g_form.setValue('resolved_by', g_user.userID);

gsftSubmit(null, g_form.getFormElement(), 'resolve_incident'); //MUST call the 'Action name' set in this UI Action
}

//Code that runs without 'onclick'
//Ensure call to server-side function with no browser errors
if (typeof window == 'undefined')
serverResolve();

function serverResolve(){
current.incident_state = IncidentState.RESOLVED;
current.state = IncidentState.RESOLVED;
current.update();
current.resolved_by = gs.getUserID();
}

 

Kind regards,

 

Pierre

Omkar Mone
Mega Sage

Hi Pierre

 

Check the below ss for reference where you need to put the condition -

find_real_file.png

 

Regards,

Omkar Mone

Hi Omkar,

 

I already have this in the condition. How and where to I add this please.

Onclick: resolveIncident();

 

Condition:

(current.incident_state != IncidentState.NEW && current.incident_state != IncidentState.CLOSED && current.incident_state != IncidentState.RESOLVED) && (gs.hasRole("itil") || gs.hasRole("itil_admin") || current.caller_id == gs.getUserID())

 

This is the script

function resolveIncident(){
	//Set the 'Incident state' and 'State' values to 'Resolved', and display mandatory fields
	g_form.setValue('incident_state', 6);
	g_form.setValue('state', 6);
	g_form.setValue('resolved_by', g_user.userID);
	
	gsftSubmit(null, g_form.getFormElement(), 'resolve_incident'); //MUST call the 'Action name' set in this UI Action
}

//Code that runs without 'onclick'
//Ensure call to server-side function with no browser errors
if (typeof window == 'undefined')
	serverResolve();

function serverResolve(){
	current.incident_state = IncidentState.RESOLVED;
	current.state = IncidentState.RESOLVED;
	current.update();
	current.resolved_by = gs.getUserID();
}

Hi Pierre,

 

Instead of the condition you have, in the incident_state can you try with

(current.incident_state != '1' && current.incident_state != '7' && current.incident_state != '6') && (gs.hasRole("itil") || gs.hasRole("itil_admin") || current.caller_id == gs.getUserID())

 

Let me know if that helped.

 

Regards,

Omkar Mone