ASA5
Kilo Sage

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 :

getListColumns(String tableName, String 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 😉

 

Hope it will help 😉

Comments
samwallace881
Giga Expert

That is exactly what I needed!

GTSPerformance
Tera Guru

Caution, the free related list widget provided by NewRocket has a bug. It does not work with defined related lists. It can potentially cause performance degradation.
See the following article for a potential customization to fix it:
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB1561435

Version history
Last update:
‎03-18-2019 05:36 AM
Updated by: