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

Peter Bodelier
Giga Sage

UI Action display conditions are only evaluated on form change. There is no way to change that without reading the form.

 

You can however re-evaluate the condition before execution, to make sure nothing 'wrong' happens by using property glide.security.strict.actions.

 

See for you reference this article.


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

So can we do something like when we save incident form after changing to cancel state then the UI action become hidden?

Yes, when you save the form gets reloaded. So this means that the conditions of your UI Action will be re-evaluated. So it can be hidden if the conditions evaluate to false.

So based on your initial script the condition would be something like

current.state != 9;


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

We already had a condition in the ui action I mentioned, I added to it the cancel state part : 

&& current.incident_state != IncidentState.Cancelled

But it's not working. It is working fine on resolved and closed state but not cancel state. When I move the incident to resolve state or close state the button gets hidden but this is not working on cancel state

(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())