controlling UI action visibility from related list changes
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
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.
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
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.
Kaushal Kumar Jha - ServiceNow Consultant - Lets connect on Linkedin: https://www.linkedin.com/in/kaushalkrjha/