Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Hide Variable Editor / form section on RITM and Task using Catalog client script

Madhan007
Tera Contributor

Hi Everyone, 

My requirement is to hide  catalog variables / variable editor / whole section (anyone is fine) for one catalog item in RITM and Task views based on a condition. I created an on load catalog client script applies on RITM  and Task view. how to hide the catalog variables / variable editor / whole section ?

I tried g_form.setDisplay('variable_editor', false)  // did not work
please pour your insights

Thank you!!

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Madhan007 

there is no direct way for this.

You will have to use DOM manipulation for this and DOM is not recommended.

If you still want then this will work in client side

Note: Isolate Script Field Should be False for DOM to run

AnkurBawiskar_4-1761307095566.png

 

// hide
document.getElementsByClassName('veditor_header')[0].style.display = 'none';
document.getElementsByClassName('veditor_body')[0].style.display = 'none';

// show
document.getElementsByClassName('veditor_header')[0].style.display = '';
document.getElementsByClassName('veditor_body')[0].style.display = '';

Before:

AnkurBawiskar_2-1761307000993.png

 

 

After: when I ran the code it's gone

AnkurBawiskar_3-1761307012432.png

 

OR

If you don't want to use DOM then use this

1) add the variable editor in a new form section

2) then use this to show/hide the section. section is hidden variable editor is gone

g_form.setSectionDisplay('variables', false); // use correct section name

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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

View solution in original post

7 REPLIES 7

@Sarthak Kashyap 

thanks for sharing the same solution again which I already shared.

Any reason to repeat the same again as that might confuse the member who asked the question?

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

Hi @Ankur Bawiskar ,

 

My intension is not coping your answer, I checked the classname is same and I checked and research that sometime macro run late so I added the setTimeOut function. So I added some extra things in my answer.

 

Thanks,

Sarthak

@Sarthak Kashyap 

timeout should help in onLoad client script

thanks for clarifying

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