getRelatedListNames() returning REL:<sys_id> and how to handle

Kit G
Mega Guru

Hi all,

 

The goal

Currently I have a need to hide tabs (related lists) from a case view in a custom workspace. The tabs are to be hidden based on a user having a delivery role. This is so delivery users can review a case but have a stripped back version of the view.

 

Whats been done

Code example

try {
	g_form.hideRelatedList('interaction');
	g_form.hideRelatedList('sys_email');
	var relatedLists = g_form.getRelatedListNames();
		for (var r = 0; r < relatedLists.length; r++) {
			//g_form.addInfoMessage(relatedLists[r]);
			if (relatedLists[r] == 'REL:37815ea2eb323100a618afcef106fe93') {
				//do nothing
				g_form.addInfoMessage('did not hide: ' + relatedLists[r]);
			}
			else {
				if (testMode == true) {
					//do nothing
				}
				else {
					g_form.hideRelatedList(relatedLists[r]);
					g_form.addInfoMessage('hid: ' + relatedLists[r]);
				}
			}
		}
	}
	catch (error) {
		g_form.addErrorMessage('An error occurred while retrieving related lists: ' + error.message);
	}

 

Questions:

The above example works however I have had to hardcode the RE:<sys_id> value to have it work. This is not as dynamic or extensible as I would like.

  1. Is this the best method to hide related lists, relationships and tabs across workspaces and form views etc.
  2. This relatedLists = g_form.getRelatedListNames(); returns REL:<sys_id> values for some but not all  
1 ACCEPTED SOLUTION

Kit G
Mega Guru

hey @Kirby R @Ankur Bawiskar @Santosh Oraon ,

 

Just an FYI on this I have highlighted the solution I went with below. Instead of hardcoding sys_id's I went with the option to hide them all and then display the ones I wanted. Although this is a bit inefficient it felt like the lesser of 2 evils.

 

I also looked at removing the related lists from the workspace view but as the impacted other workspace's views of the same case it was not suitable.

 

function onCondition() {
	//if the user has the delivery role and is not and admin begin the steps to impose the delivery view
	if (g_user.hasRole('x_tafe5_alternat_0.delivery_user') && !g_user.hasRole('admin')) {
		//####### Hide related lists##########
		try {
			//get all the related lists on the form so they can be hidden
			var relatedLists = g_form.getRelatedListNames();
			//iterate through each related list and set it to be hidden so that tabs in  my workspace are not shown
			for (var r = 0; r < relatedLists.length; r++) {
				//hide the related list
				g_form.hideRelatedList(relatedLists[r]);
			}
		}
		catch (error) {
			//if an error is caught display a message with the relevant details for troubleshooting
			g_form.addErrorMessage('An error occurred while retrieving related lists: ' + error.message);
		}
		//set the related lists to be displayed as visible
		g_form.showRelatedList('sn_customerservice_task.parent');
		g_form.showRelatedList('sys_email');
	}
}

 

Cheers

View solution in original post

8 REPLIES 8

Hi Santosh,

 

Thanks for this - I have already created the UI policy and the example code I provided comes from the script within that.

 

Cheers

Kit

Ankur Bawiskar
Tera Patron
Tera Patron

@Kit G 

the sysId won't change so you can hard-code it

Another way is to store the sysId in system property and then use GlideAjax to get that sysId and then use in client side.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hey @Ankur Bawiskar,

 

Thanks for this, I have considered hard coding it just does not seem in line with best practices. Check out my reply to Kirby where I provided some more details.

 

I highlighted some other options in there however I may also (if customers are happy with it) just remove the related lists from the case altogether if they are not needed.

 

Cheers

Kit

Kit G
Mega Guru

hey @Kirby R @Ankur Bawiskar @Santosh Oraon ,

 

Just an FYI on this I have highlighted the solution I went with below. Instead of hardcoding sys_id's I went with the option to hide them all and then display the ones I wanted. Although this is a bit inefficient it felt like the lesser of 2 evils.

 

I also looked at removing the related lists from the workspace view but as the impacted other workspace's views of the same case it was not suitable.

 

function onCondition() {
	//if the user has the delivery role and is not and admin begin the steps to impose the delivery view
	if (g_user.hasRole('x_tafe5_alternat_0.delivery_user') && !g_user.hasRole('admin')) {
		//####### Hide related lists##########
		try {
			//get all the related lists on the form so they can be hidden
			var relatedLists = g_form.getRelatedListNames();
			//iterate through each related list and set it to be hidden so that tabs in  my workspace are not shown
			for (var r = 0; r < relatedLists.length; r++) {
				//hide the related list
				g_form.hideRelatedList(relatedLists[r]);
			}
		}
		catch (error) {
			//if an error is caught display a message with the relevant details for troubleshooting
			g_form.addErrorMessage('An error occurred while retrieving related lists: ' + error.message);
		}
		//set the related lists to be displayed as visible
		g_form.showRelatedList('sn_customerservice_task.parent');
		g_form.showRelatedList('sys_email');
	}
}

 

Cheers