Hiding Related Lists and Embedded Lists

///Hiding Related Lists and Embedded Lists

Hiding Related Lists and Embedded Lists

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…

Related Lists
Embedded Lists

Hiding and Showing Related Lists

There are some built-in methods for showing and hiding standard related lists. Simply provide the table name of the related list you want to hide (or the ‘Related list’ field value from the list control in some cases). One limitation you’ll want to be aware of is that these methods hide the related list, but they don’t hide the tab if you’re using tabbed forms.

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

g_form.hideRelatedList('task_ci');

Showing a Related List

g_form.showRelatedList('task_ci');

Hiding and Showing Embedded Lists

These scripts were created by me to show and hide form-embedded lists. In this case, it’s easier to target the label of the embedded list so you need to use the list label instead of the table name.

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

var list = $$('div[tab_caption="Affected CIs"]')[0];
if(list.hasClassName('embedded')){
   list.hide();
}

Showing an Embedded List

var list = $$('div[tab_caption="Affected CIs"]')[0];
if(list.hasClassName('embedded')){
   list.show();
}
By | 2018-07-09T14:59:59-06:00 June 15th, 2011|Categories: Client scripts|Tags: , , |10 Comments

About the Author:

10 Comments

  1. Torsten Brosow June 15, 2011 at 10:25 am - Reply

    Hi

    are you using jquery in the script?

    I thought jquery has been replaced in the June release!

    • Mark Stanger June 15, 2011 at 10:27 am - Reply

      I’m using the Prototype library.

  2. brumiou October 12, 2011 at 3:49 am - Reply

    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

    • Mark Stanger October 12, 2011 at 6:30 am - Reply

      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.

  3. Dan Berglin May 8, 2013 at 7:18 am - Reply

    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

    • Dan Berglin May 8, 2013 at 7:33 am - Reply

      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

  4. Amisha Parekh July 31, 2013 at 11:28 am - Reply

    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

  5. Sandeep May 11, 2017 at 1:14 pm - Reply

    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 ?

    • Mark Stanger May 11, 2017 at 1:35 pm - Reply

      No way that I’m aware of. You might ask on the ServiceNow community.

Leave A Comment