Skip to content

Commit 30e2a0b

Browse files
author
kmxo
committed
related list
1 parent 3bf5729 commit 30e2a0b

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

Server Side/HideRelatedList/readme.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
# How to hide a Related List
3+
4+
Do you know about the Related List that displays people who can approve or reject a document?
5+
6+
Recently a scenario came up where the developer needed to prevent the employee who created a record from approving that document.
7+
It wasn't common because usually the operational level creates the document while a manager approves it.
8+
Leaving this question of personas aside and focusing on the problem, what would be a possible solution?
9+
10+
The first workaround that came to my mind was to hide the Approval list if the user who registered was viewing his own record.
11+
A workaround is not the ultimate solution. Just a palliative fix while we find time to think about the ideal one.
12+
13+
The action plan
14+
15+
1) Every record has a field called sys_created_by;
16+
2) On the front-end (client side) we have access to an API called Glide User that has some information about the logged in user. Among them is the name in the userName property.
17+
18+
What if we create a Client Script of type onLoad* that compares these two fields and, if they are the same, simply hides the Approvers related list?
19+
To see the related list name created for your table, you can access the platform and go to System UI > Related lists.
20+
21+
22+
Now that you know the related list name, your script would look like script.js in this folder.
23+
24+
To get the value of the sys_created_by field it must be in the form. You can leave it read-only or even hidden but it must exist on the form.
25+
26+
A Client Script of type onLoad is executed whenever the form is opened.

Server Side/HideRelatedList/script.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
function onLoad() {
2+
3+
var createdBy = g_form.getValue('sys_created_by');
4+
var loggedUser = g_user.userName;
5+
if (createdBy == loggedUser) {
6+
g_form.hideRelatedList('put your related list name here');
7+
}
8+
9+
}

0 commit comments

Comments
 (0)