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

I raised a case with servicenow for this, thanks for helping me on this

I just checked the oob script include "IncidentStateSNC" in dev and sandbox. In this value of both closed and cancelled state is set as "7". But in oob instances i checked value of canceled state is set at '8' in script include, But the script is set at read only so I can't edit it. I guess that is causing the issue? Any suggestion on how to fix it

Try this 

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

 


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

Mayu
Tera Guru
Tera Guru

Write a client script add a code

g_form.setDisplay('button_id',false);

Mark helpful.