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

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

Hey @Ankur Bawiskar , Thanks for your reply.

Madhan007_0-1761311090134.png
I kept the variable editor formatter inside Request Information section and trying to hide it using g_form.setSectionDisplay('Request Information', false), but its not working. should i use backend name of section ? if so, where can i find it ?

Thank you!!

 

@Madhan007 

section name is name of section with lowercase and space substituted with underscore

so it will be this

g_form.setSectionDisplay('request_information', false)

💡 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

Sarthak Kashyap
Mega Sage

Hi @Madhan007 ,

 

I tried your problem in my PDI and it is working fine for me please check below code 

 

 

Create OnLoad Client script on sc_req_item table and add below code

function onLoad() {


    setTimeout(function() {
        var veList = document.getElementsByClassName('veditor_body');

        if (veList && veList.length > 0) {
            for (var i = 0; i < veList.length; i++) {
                veList[i].style.display = 'none';
            }
        }
    }, 300);
}

 

Result 

After:

SarthakKashyap_0-1761308521253.png

Below: 

SarthakKashyap_1-1761308549104.png

Please mark my answer correct and helpful if this works for you

Thanks and Regards,

Sarthak