Free Service Portal Widget: Related Lists

nathanfirth
Tera Guru

To help contribute back to the community, we're going to try to develop and give away one new widget per month.

For January we have developed the "Related List" widget, which allows you to display related lists on the form page in Service Portal.

Example below from a service catalog request:

Screen Shot 2017-01-12 at 10.20.55 AM.png

To download the widget, it's available on ServicePortal.io: Free Widget of the Month - ServicePortal.io - Service Portal, CMS, and Custom Apps

65 REPLIES 65

Hey so what did you have to do to include the _ library? I found that as of Madrid, Servicenow includes two versions of underscore for studio. Did you still have to add the gs.include statement?

I found my issue. Servicenow has their underscore libraries not in global scope. Adding one to global worked.

@arthurcheung However, apparently as of Madrid if you make a script include called "_" it breaks the Studio functions in Servicenow because they rely on a different script include called _. Did you know a workaround to this issue or if we can just rename the _ in the widget server script?

I think I found that you can name it underscore and replace the _ in the script with it.

 

/***include the underscore library so things work ***/
gs.include('underscore');
	data.f = {};
	data.table = $sp.getParameter("t") || $sp.getParameter("table") || options.table;
	data.sys_id = $sp.getParameter("sys_id") || options.sys_id;
	data.query = $sp.getParameter("query");

	if (!data.table || !data.sys_id)
		return;

	var f = $sp.getForm(data.table, data.sys_id, data.query);
	data.f = f;
	data.related_lists = f._related_lists;
	
	/** Snippe to add the related list when from a defined relationship **/
	if (underscore(data.related_lists).where({"type": "REL"}).length > 0) {
       data.related_lists = underscore(data.related_lists).map(function (item) {

               if (item.type === 'REL') {
                       item.definedRelationshipFilter = extractDefinedRelationshipsQuery(item.apply_to, item.apply_to_sys_id, item.table, item.relationship_id);
               }

               return item;
       });
}   

KS7
Kilo Contributor

Hi Arthur,

 

I am trying to use this widget in Rome version and as suggested by you I have created a script include named "underscore-min.js and renamed it "_".

I am not sure if I need to call this script include in server side widget.

But I getting below error. Could you pls help me out where I am going wrong

 

find_real_file.png

Here is the snipped of the server side 

 

find_real_file.png