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

Kirby R
Kilo Sage

@Kit G

 

1. yes. you would want use sys id since it the unique field. if you use name lets say "task" then there could be multiple related list labeled task

 

2. if im not mistaken, rel:sysid is only for custom relationships. you dont get this in other type of relationship like 1 to many.

Hey @Kirby R ,

 

Thanks for the information I wanted to add more to my post but had colleagues bugging me to go to lunch.... 🤣
I wanted to add a few more details to the post but does not look like I can edit it after submission.
Here is a sample of the values the command 'relatedLists = g_form.getRelatedListNames();' returns. Note the // is just me identifying the table the REL referenced.

task_sla.task
sn_customerservice_task.parent
REL:35e23f2a873303002ae97e2526cb0b1e //interaction
REL:060ac8df7780101033809b30691061e2 //email_draft
REL:37815ea2eb323100a618afcef106fe93 //sys_email
task_m2m_skill.task

Now I wanted to cycle through these and specify the table names I didnt want to hide but as g_form.getRelatedListNames() returns the REL's I cant use the names. The reason I wanted to do that as I believe its bad practice to hardcode sys_id as there are possibilities they are different between environments. I also wanted to retrieve all the related items so I would handle other lists being added over time without having to revisit the UI policy.

 

Alternate solutions I can use include:

  1. Hide them all and then show the ones I specify (would work seems a little inefficient though)
  2. Look up the relationship using the REL:<sys_id> so I can use the name (even more inefficient)
  3. Validate the sys_id's are the same across my environments and hardcode (would work I just dont like it as mentioned above 😀)

Ultimately it would be good if I could pull the table value back using command but does not seem to be the case.

I will check out the relationships and see if they are OOTB or customised and see if that leads me anywhere.

Cheers

Kit

 

alternate solutions 1 and 2 seems fine. although point 3 seems wrong. if you follow best practice you should have same sys_id across environments for a single component. the only they would we different sysid is if you directly create each relationship in each environment and not using updateset to move it.

 

 

Santosh Oraon
Tera Expert

hi @Kit G To hide related list use ui policy advance scripts you can add your logic and control the visibilty of related list. Below is one small example
****************************************************************************************************

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

Regards,
Santosh Oraon

SantoshOraon_0-1751597601630.png