From d39c0aa427c664a752e5f5e2280cf77b741fc427 Mon Sep 17 00:00:00 2001 From: kmxo Date: Tue, 1 Oct 2024 17:42:05 -0300 Subject: [PATCH 1/4] hide --- Server Side/HideRelatedList/readme.md | 22 ++++++++++++++++++++++ Server Side/HideRelatedList/script.js | 10 ++++++++++ 2 files changed, 32 insertions(+) create mode 100644 Server Side/HideRelatedList/readme.md create mode 100644 Server Side/HideRelatedList/script.js diff --git a/Server Side/HideRelatedList/readme.md b/Server Side/HideRelatedList/readme.md new file mode 100644 index 0000000000..591ef8cebe --- /dev/null +++ b/Server Side/HideRelatedList/readme.md @@ -0,0 +1,22 @@ +# How to hide a Related List + +Do you know about the Related List that displays people who can approve or reject a document? +Recently a scenario came up where the developer needed to prevent the employee who created a record from approving that document. +It wasn't common because usually the operational level creates the document while a manager approves it. +Leaving this question of personas aside and focusing on the problem, what would be a possible solution? + +The first workaround that came to my mind was to hide the Approval list if the user who registered was viewing his own record. +A workaround is not the ultimate solution. Just a palliative fix while we find time to think about the ideal one. + +The action plan + +1) Every record has a field called sys_created_by; +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. +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? +To see the related list name created for your table, you can access the platform and go to System UI > Related lists. + +Now that you know the related list name, your Client Script would look like the script file in this folder. + +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. + +A Client Script of type onLoad is executed whenever the form is opened. \ No newline at end of file diff --git a/Server Side/HideRelatedList/script.js b/Server Side/HideRelatedList/script.js new file mode 100644 index 0000000000..2ea7d3c1b8 --- /dev/null +++ b/Server Side/HideRelatedList/script.js @@ -0,0 +1,10 @@ +function onLoad() { + + var createdBy = g_form.getValue('sys_created_by'); + var loggedUser = g_user.userName; + + if (createdBy == loggedUser) { + g_form.hideRelatedList('put your related list name here'); + } + + } \ No newline at end of file From a4c99ee9aa8fbbbcd41f71bac49885fdf6fdbf20 Mon Sep 17 00:00:00 2001 From: kmxo Date: Tue, 1 Oct 2024 17:45:05 -0300 Subject: [PATCH 2/4] fix related lists --- Server Side/HideRelatedList/readme.md | 1 + Server Side/HideRelatedList/script.js | 1 + 2 files changed, 2 insertions(+) diff --git a/Server Side/HideRelatedList/readme.md b/Server Side/HideRelatedList/readme.md index 591ef8cebe..24956fbfc1 100644 --- a/Server Side/HideRelatedList/readme.md +++ b/Server Side/HideRelatedList/readme.md @@ -12,6 +12,7 @@ The action plan 1) Every record has a field called sys_created_by; 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. + 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? To see the related list name created for your table, you can access the platform and go to System UI > Related lists. diff --git a/Server Side/HideRelatedList/script.js b/Server Side/HideRelatedList/script.js index 2ea7d3c1b8..02170e6b60 100644 --- a/Server Side/HideRelatedList/script.js +++ b/Server Side/HideRelatedList/script.js @@ -7,4 +7,5 @@ function onLoad() { g_form.hideRelatedList('put your related list name here'); } + } \ No newline at end of file From b2e4cc1d84d1ecb7a25416258938d015344275c4 Mon Sep 17 00:00:00 2001 From: kmxo Date: Tue, 1 Oct 2024 17:49:28 -0300 Subject: [PATCH 3/4] fix --- Server Side/HideRelatedList/readme.md | 2 +- Server Side/HideRelatedList/script.js | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/Server Side/HideRelatedList/readme.md b/Server Side/HideRelatedList/readme.md index 24956fbfc1..5f3a3802d0 100644 --- a/Server Side/HideRelatedList/readme.md +++ b/Server Side/HideRelatedList/readme.md @@ -8,7 +8,7 @@ Leaving this question of personas aside and focusing on the problem, what would The first workaround that came to my mind was to hide the Approval list if the user who registered was viewing his own record. A workaround is not the ultimate solution. Just a palliative fix while we find time to think about the ideal one. -The action plan +# The action plan 1) Every record has a field called sys_created_by; 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. diff --git a/Server Side/HideRelatedList/script.js b/Server Side/HideRelatedList/script.js index 02170e6b60..315166961a 100644 --- a/Server Side/HideRelatedList/script.js +++ b/Server Side/HideRelatedList/script.js @@ -1,11 +1,7 @@ function onLoad() { - var createdBy = g_form.getValue('sys_created_by'); var loggedUser = g_user.userName; - if (createdBy == loggedUser) { g_form.hideRelatedList('put your related list name here'); } - - } \ No newline at end of file From 6235457cf09ef2c02bd9cf1ec48b47838f664dd1 Mon Sep 17 00:00:00 2001 From: kmxo Date: Tue, 1 Oct 2024 17:55:45 -0300 Subject: [PATCH 4/4] fix --- Server Side/HideRelatedList/readme.md | 1 + Server Side/HideRelatedList/script.js | 1 + 2 files changed, 2 insertions(+) diff --git a/Server Side/HideRelatedList/readme.md b/Server Side/HideRelatedList/readme.md index 5f3a3802d0..4a3c1b6f5c 100644 --- a/Server Side/HideRelatedList/readme.md +++ b/Server Side/HideRelatedList/readme.md @@ -8,6 +8,7 @@ Leaving this question of personas aside and focusing on the problem, what would The first workaround that came to my mind was to hide the Approval list if the user who registered was viewing his own record. A workaround is not the ultimate solution. Just a palliative fix while we find time to think about the ideal one. + # The action plan 1) Every record has a field called sys_created_by; diff --git a/Server Side/HideRelatedList/script.js b/Server Side/HideRelatedList/script.js index 315166961a..729ceb3140 100644 --- a/Server Side/HideRelatedList/script.js +++ b/Server Side/HideRelatedList/script.js @@ -4,4 +4,5 @@ function onLoad() { if (createdBy == loggedUser) { g_form.hideRelatedList('put your related list name here'); } + } \ No newline at end of file