logo

NJP

Configure the list layout for related list in Service Portal.

Import · Mar 18, 2019 · article

Hello,

There is an amazing widget to use related lists on service portal https://serviceportal.io/downloads/related-list-widget/.

I would like to share my experience using this widget, especially when you want to configure the list layout for a related list on the Service Portal view.

When I tried to configure Service Portal view(using configure>list layout) to show only some fields , the widget doesn't show me the fields that I configured, and instead of that it shows fields that are configured on the default view.

After some debugging I found that $sp.getListColumns doesn't return the appropriate list of fields, as it accept only tow parameters, table and view :

Then I added a function which takes also the parent table of the related list as parameter :

function getListOfColumn(table,parent){

    var fields = [];
    var gr = new GlideRecord("sys_ui_list");
    gr.addQuery("name",table);
    gr.addQuery("parent",parent);
    gr.addQuery("view.name","sp");

    gr.query();

    if(gr.next()){

        var grElement = new GlideRecord("sys_ui_list_element");
        grElement.addQuery("list_id.sys_id",gr.sys_id.toString());
        grElement.orderBy("position");
        grElement.query();

        while(grElement.next()){

            fields.push(grElement.getDisplayValue("element"));
        }

    }

    if(fields.length!=0)
        return fields.join();
    else
        return "";
}

Then I called the function when related list are constructed :

for (var i in data.related_lists) {

var list = data.related_lists[i];

//get the list of Column to show in the header  
var listOfColumn =  getListOfColumn(list.table,data.table);

....

And the last thing is to add the list of column as parameter of the data table widget :

var params = {
 table: list.table,
 filter: list.definedRelationshipFilter || (list.field+"="+data.sys_id),
 view: 'sp',
 title: list.label,
 show_new: true,
 fields: listOfColumn
};

When the Service Portal view is configured for a related list, modifications are visible on the Service Portal image

Hope it will help image

View original source

https://www.servicenow.com/community/developer-articles/configure-the-list-layout-for-related-list-in-service-portal/ta-p/2329683