How to hide UI action from UI policy ??

Hritik1
Tera Contributor

Hello Community,

I have a requirement as below :

I wish to hide custom UI action on change record table. Whenever the condition is 'Subject to Gxp == Yes' the ui action must disable/hide.

I have the below code prepared for it :

find_real_file.png

The issue is it only hides the top button and not the bottom button. I even tried querying the button itself but no luck 😞 

Please help me achieve this requirement ...

 

1 ACCEPTED SOLUTION

suvro
Mega Sage
Mega Sage

Set the condition in the condition field of the UI Action not via client script. (current.subject_to_gxp  == 'No')

find_real_file.png

View solution in original post

7 REPLIES 7

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

DOM is not recommended practice.

If you still require then ensure Isolate Script field is Set to False for your UI policy

Use this script in Execute if True

Ensure you give the correct action name - I have given test; you give your UI action name

function onCondition() {
$j('[data-action-name=test]').hide();
}

Use this script in Execute if False to show

function onCondition() {
$j('[data-action-name=test]').show();
}

find_real_file.png

Regards
Ankur

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

Hi,

Usually UI actions are shown based on condition field

If you wish to show/hide it based on some field change then UI policy is required; but it would require DOM manipulation which is not recommended.

If you wish not to show/hide then ensure you add correct condition in the UI action so that it shows only when that condition evaluates to true

Regards
Ankur

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

Sulabh Garg
Mega Sage
Mega Sage

Hello Hritik,

Why you are writing a UI policy to hide the UI action. Instead you can specify the conditions under UI actions only to hide the UI action.

Here in the UI policy script you are using DOM to hide the UI action which is not the best practice and it may vary the results based on the browsers/upgrades.

Hope it helps!!

 

Please Mark ✅ Correct/helpful, if applicable, Thanks!! 

Regards

Sulabh Garg

Please Mark ✅ Correct/helpful, if applicable, Thanks!!
Regards
Sulabh Garg

Jaspal Singh
Mega Patron
Mega Patron

Why don't you directl pass the condition in the Condition field of the UI Action.

No need of DOM manipulation