The CreatorCon Call for Content is officially open! Get started here.

Can I hide a tab using a UI Policy

johnrob18
Giga Guru

I have a requirement to hide /show tabs as a result of selection - can I achieve this through a UI policy?

1 ACCEPTED SOLUTION

Harsh Vardhan
Giga Patron

i would suggest here go with onChange() client script. if you are open with the script then try with client script rather UI policy

 

var sections = g_form.getSections(); // will you the sections

based on your section array index you can define like this

sections[5].style.display='block'; // hide

sections[5].style.display='none'; // not hide

 

note: sections[5] // 5 is the sequence of your section, make sure you mention the write sequence , it start from 0 index.

 

 

for reference you can check with below link

 

https://community.servicenow.com/community?id=community_question&sys_id=7bc5c721db1cdbc01dcaf3231f96...

https://www.servicenowguru.com/scripting/client-scripts-scripting/showhide-form-section/

View solution in original post

6 REPLIES 6

Tim Whonder
Giga Expert

I was recently able to do this using a UI Policy. I spent hours figuring out a lengthy client script. I eventually got it. Then realized this was faster and easier to maintain.

 

On the When to apply tab, add your conditions.

On the Script tab, select "Run Scripts" then enter the following

Execute if True

function onCondition() {
g_form.setSectionDisplay('insert_firsttabnamehere', true);
g_form.setSectionDisplay('insert_secondtabnamehere', true);

}

Execute if False

function onCondition() {
g_form.setSectionDisplay('insert_firsttabnamehere', false);
g_form.setSectionDisplay('insert_secondtabnamehere', false);

}

 @Risk Busters I agree with this post. 

I think that both the client script and UI policy are valid options. 

However, to your point I think that if you decide to go the client script direction you will have to create two separate client scripts. There will be an OnLoad script as well as an OnChange client script.  

Whereas If you go the UI policy route you will have the condition evaluated on load as well as on change. Therefore it satisfies both conditions and saves you the effort of creating and maintaining two separate client scripts .