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

I tried to the same thing for Non admin role.

Here is my script but its not working. Is there anything wrong with the script?
function onLoad() {
//Type appropriate comment here, and begin script below
if(!g_user.hasRole('admin')){
g_form.hideRelatedList(sysapproval_approver.sysapproval);
g_form.hideRelatedList(sysapproval_group.parent);
}
}


CapaJC
ServiceNow Employee
ServiceNow Employee

One thing I see is that sysapproval_approver.sysapproval and the similar parameter in the following line likely need to be quoted: "sysapproval_approver.sysapproval".


Ruchi19
Mega Contributor

opps..my bad..thanks it works 🙂