Hiding UI action based on conditions

Ashwi
Tera Contributor

I have requirement to make hide UI action from form  if logged In user and assigned to users are same. UI action is not sc_task table. Is it good practice if we make changes in OOTB UI action? What are all possible ways?

Thanks, Bilbo

1 ACCEPTED SOLUTION

AbhishekGardade
Giga Sage

Hello Bilbo,

1. To achieve your requirement, you need to add a simple condition: current.assigned_to!=gs.getUserID()  condition Builder.

2. You need to override that UI action as its not best practice to modify any OOTB UI action.

3. Create New UI action and override with OOTB UI action that you want to hide

Alternative way for hiding UI action is with the help of DOM manipulation. Its not recommended by ServiceNow.

1. You need to write onLoad Client script and Make sure that you uncheck the field ISOLATED SCRIPT:

2. Add following code:

/Remove the 'Submit' button 
var items = $$('BUTTON').each(function(item){
   if(item.innerHTML.indexOf('Submit') > -1){
      item.hide();  
   }
});

3. Check out this useful blog:

https://www.servicenowguru.com/scripting/client-scripts-scripting/removing-form-buttons/

Please mark as Correct Answer/Helpful, if applicable.
Thanks!

Abhishek

 

Thank you,
Abhishek Gardade

View solution in original post

5 REPLIES 5

SanjivMeher
Kilo Patron
Kilo Patron

You can create your own UI action, if the same UI action is used in other modules as well. Just make sure the action name are same.

Then add condition as current.assigned_to!=gs.getUserID()


Please mark this response as correct or helpful if it assisted you with your question.

DirkRedeker
Mega Sage
Hi Additionally, to the notes from Sanjiv, there is a Related List on the definition Form of the UI Action called 'UI Action Visibility'. There, you can define, on which View, the UI Action is visible, if you intend to show only on specific Views of the Table. Let me know, if that was helpful and mark my answer as correct and helpful. BR Dirk

AbhishekGardade
Giga Sage

Hello Bilbo,

1. To achieve your requirement, you need to add a simple condition: current.assigned_to!=gs.getUserID()  condition Builder.

2. You need to override that UI action as its not best practice to modify any OOTB UI action.

3. Create New UI action and override with OOTB UI action that you want to hide

Alternative way for hiding UI action is with the help of DOM manipulation. Its not recommended by ServiceNow.

1. You need to write onLoad Client script and Make sure that you uncheck the field ISOLATED SCRIPT:

2. Add following code:

/Remove the 'Submit' button 
var items = $$('BUTTON').each(function(item){
   if(item.innerHTML.indexOf('Submit') > -1){
      item.hide();  
   }
});

3. Check out this useful blog:

https://www.servicenowguru.com/scripting/client-scripts-scripting/removing-form-buttons/

Please mark as Correct Answer/Helpful, if applicable.
Thanks!

Abhishek

 

Thank you,
Abhishek Gardade

DirkRedeker
Mega Sage
Hi And here is another interesting information. You can override existing UI Actions. In that way, you do not need to change the OOB UI Action. You can override existing UI Actions in the field 'Overrides' in the UI Action definitions Form. Let me know if that answered your question and mark my answer as correct and helpful. BR Dirk