I
just saw a question on the ServiceNow forums asking how you could show and hide an embedded related list on a form. I just created some client scripts to accomplish this task so I figured I would share them here. I’ll also review the methods and limitations for showing and hiding standard related lists using client scripting.
First of all, if you need to understand the basics about these concepts I’ll refer you to the ServiceNow wiki. Here are a couple of links that should be useful…
Hiding and Showing Related Lists
I’m using the ‘Affected CIs’ related list as an example in these scripts. Replace ‘task_ci’ below with the table name of your related list.
Hiding a Related List
Showing a Related List
Hiding and Showing Embedded Lists
I’m using the ‘Affected CIs’ related list as an example in these scripts. Replace ‘Affected CIs’ below with the label of your embedded list.
Hiding an Embedded List
if(list.hasClassName('embedded')){
list.hide();
}
Showing an Embedded List
if(list.hasClassName('embedded')){
list.show();
}
Hi
are you using jquery in the script?
I thought jquery has been replaced in the June release!
I’m using the Prototype library.
Hi,
it’s really interesting, thanks!
Do you also know a way to put an embedded list read-only?
I’ve tried many things, but no results :s
I haven’t ever tried to do that. I think it would probably end up being some pretty advanced client script to do it though. I don’t think there’s a simple way.
Hi,
got an issue with embedded lists.
Im working on a new “Relations” tab for Tasks. The customer dont want to use the “Related Items” UI-macro (which is hard coded!?). They want two embedded lists, one list for Parent tasks (task_rel_task.parent) and one list for Child tasks (task_rel_task.child).
Found an embedded list named “Relationships” and one called simply “Child” which displays the related tasks. Where do I even find the objects for theese, they are labeled (no ->)? Can’t find them anywhere.
Problem is, they get the same column layout as the embedded lists are the same table. I can’t apply any view. Client script for applying a different list View would maybe be a solution?
List layout/columns:
Parent
Child
Child.Short description
Parent.Short description
Result:
The “Parent” column is automagicaly hidden (!?) where it should and the “child” column as well! However, the “short description” column is’nt pretty. Both are displayed and one of the column is of course repeating the “current.short_description”.
Applying different views using some sort of script would solve this, but I dont know how. Even tried database views to simulate different tables.
Please help! I’m stuck in ServiceNow which i belived was impossible!
Kind regards,
Dan
Hi agian,
10 minutes after last post I found the way around. Speciefied two new Relationships (System Definition -> Relationships) and after that I could control the two resulting embedded list layouts separately. 🙂
Kind regards,
Dan
Hi Mark,
Is there is a way to hide all Related list with one script line or do i need to go one by one?
Thanks & Regards,
Amisha Parekh
Got it… 🙂
g_form.hideRelatedLists();
Hi,
Is there a way I can get the all the related list elements ( that are being shown on a form ) , in the UI Action that I am creating on that form ?
No way that I’m aware of. You might ask on the ServiceNow community.