The Zurich release has arrived! Interested in new features and functionalities? Click here for more

controlling UI action visibility from related list changes

gourav_toonwal
Tera Contributor

Hey Community ,
I have a requirement to control the Visibility of a UI Action.
UI action : Revert to New.

Table : change_request

 

requirement : I need to hide the UI action "revert to new" on the table "change_request" when in the related list approvers any one of the approver approves . 

 

step to reproduce : 

1 create a normal change 

2. When record is in new state add a manual approver to the approver list.

3. complete any task (if any ) and move to assess state

4. button will be visible in form context menu.

Screenshot 2025-09-04 192921.png

 

the idea is when some approved the record there should be no chance to revert the the record and make the changes in record.
Any insight would be appreciated.

Thank you 

2 ACCEPTED SOLUTIONS

Ankur Bawiskar
Tera Patron
Tera Patron

@gourav_toonwal 

in the UI action condition you can call script include function

That script include function will check if this CHG is approved by 1 approver

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

View solution in original post

@gourav_toonwal 

UI action condition evaluates only once when form loads.

Button is on CHG table so when in related list somebody approves and if form doesn't reload then it won't work.

That's OOTB behavior.

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

View solution in original post

6 REPLIES 6

Bhuvan
Kilo Patron

@gourav_toonwal 

 

You can tweak the below script includes to match your conditions and use it in UI action

 

https://www.servicenow.com/community/developer-forum/show-ui-action-only-if-the-task-has-an-active-a...

 

If this helped to answer your query, please mark it helpful & accept the solution. 

 

Thanks,

Bhuvan

kaushal_snow
Mega Sage

Hi @gourav_toonwal ,

 

Use a Script Include called from the UI Action....

Create a Script Include, for example:

var ApproverUtils = Class.create();
ApproverUtils.prototype = {
initialize: function() {},

hasApproverApproved: function(changeSysId) {
var gr = new GlideRecord('sys_approval_approver');
gr.addQuery('document_id', changeSysId);
gr.addQuery('state', 'approved'); // adjust the field based on your table schema
gr.setLimit(1);
gr.query();
return gr.next();
},

type: 'ApproverUtils'
};

Call this in your UI Action Condition:

!ApproverUtils.hasApproverApproved(current.sys_id)


This ensures Revert to New only appears when no approver has yet approved.....


Alternative Approach: Related List UI Control.

 

If you’re instead targeting a related list UI action (rather than a form level button), you can leverage the

 

Related List’s List Control options, such as:

Configuring List Control > Omit New/Edit condition with a script like:

answer = (parent.state == 'closed_complete') ? false : true;

This hides the New or Edit button on the related list when certain conditions are met....

 

If you found my response helpful, please mark it as ‘Accept as Solution’ and ‘Helpful’. This helps other community members find the right answer more easily and supports the community.

 

 

 

Thanks and Regards,
Kaushal Kumar Jha - ServiceNow Consultant - Lets connect on Linkedin: https://www.linkedin.com/in/kaushalkrjha/