Hide Ui action button on incident form on state change

PriyanshuVerma1
Tera Expert

We have a UI action button on incident form header called "Resolve Incident". We want to hide that button when State is changed to cancelled. For that I created a on change client script on incident table which is 

function onChange(control, oldValue, newValue, isLoading) {
  if (isLoading || newValue === '') {
    return;
  }
  
  // Check if the new value is "Cancel"
  if (newValue === '9') { 
    // Hide the UI action button
    g_form.setDisplay('d7e9b3701b6433004e9e97d58d4bcbcf', false);
  }
}

Now when I go to any active incident and change state to cancel, there is no change on form. Resolve button is still there. Can you guide me on how to achieve this

23 REPLIES 23

Can you help me with UI action condition to achieve that, currently the condition is :

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

 The condition is working fine for closed and resolve state but not for cancel state 

@PriyanshuVerma1 

you are using wrong spelling

it should be CANCELED

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

incidnt state.PNG

 

See the screenshot I attached in reply. The spelling in incident_state choice list is "Cancelled" , that's why I used it

That makes sense, but it leverages the 'IncidentState' Script include, it's written differently there,


Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.

It is not working. I think it's not working because in my choice list also the spelling is not what you said but i am not sure