Why my show/hide related list scripts are not working?

poornima2
Mega Expert

I have created a couple of scripts to hide/show the related lists.It is not working and creating errors.

function onLoad() {
document.getElementById('incident_wrapper').style.display = 'none';
}
I even tried using getSections() and hideRelatedList() methods.
Thanks

1 ACCEPTED SOLUTION

MB26
ServiceNow Employee
ServiceNow Employee

Here is how I got it to work. I created a client script and used the g_form.hideRelatedLists(listTableName) method, as explained in the wiki. However, sometimes the table name would work, and other times not, as in the case of your metric instance table. The question I had was, what is the "listTableName" it is referring to. I finally went into the List Control of the related list and used the "Related List" field value in place of the "listTableName" and it worked every time. In the case of the Metrics related list, it had "REL:412b7b420a258102002a5fdbfab70593" in the "Related List" field. when I put that into the hideRelateList method



g_form.hideRelatedList('REL:412b7b420a258102002a5fdbfab70593');

everything worked. So maybe try this technique to see if it works for you.


View solution in original post

7 REPLIES 7

gaidem
ServiceNow Employee
ServiceNow Employee

What is the condition for this? Most of this you can accomplish under list control.


MB26
ServiceNow Employee
ServiceNow Employee

Here is how I got it to work. I created a client script and used the g_form.hideRelatedLists(listTableName) method, as explained in the wiki. However, sometimes the table name would work, and other times not, as in the case of your metric instance table. The question I had was, what is the "listTableName" it is referring to. I finally went into the List Control of the related list and used the "Related List" field value in place of the "listTableName" and it worked every time. In the case of the Metrics related list, it had "REL:412b7b420a258102002a5fdbfab70593" in the "Related List" field. when I put that into the hideRelateList method



g_form.hideRelatedList('REL:412b7b420a258102002a5fdbfab70593');

everything worked. So maybe try this technique to see if it works for you.


For anyone wondering how to open List control: Open the list context menu in the Incidents related list and select Configure > List Control.

poornima2
Mega Expert

Awesome! Thanks MB.It worked great