AngelRodriguez
3 years agoQrew Assistant Captain
Incorporating role permissions within a button...
I'm trying to create a conditional statement to hide a button based on one of two statements being true and the user role not being equal to the admin role (ID 12). When I run this in separate browsers, one using a role other than 12 and in the other browser logged in as role 12, the button is hidden in both cases.
I'm using the Using formula - multi-select text fields documentation for the 'role' field since my variable is (var roles) a multi-select text field.
------------------------------
AR
------------------------------
I was able to solve this by flipping the logic between the "and" statement. I also realized that I only wanted to display completed or voided records if I was logged in as the admin. What I have below works.
I'm using the Using formula - multi-select text fields documentation for the 'role' field since my variable is (var roles) a multi-select text field.
var text roles = ToText(UserRoles("ID"));
If (
// Is completed or voided
([Stage] = "Completed"
or
[Voided] = true)
and
// Role with ID 12 == "Administrator"
// Not Administrator
(Left($roles,3) <> "12 " or
not Contains($roles,"; 12 ;") or
Right($roles,3) <> " 12" or
(not Contains($roles,"12") and Length($roles) = 2))
,
// Show nothing
null
,
// Else, the button should display
URLRoot() & "db/" & [_DBID_TASK_ITEM_DETAILS] & "?a=API_GenAddRecordForm&_fid_11=" & URLEncode ([Record ID#])& "&z=" & Rurl()
)
------------------------------
AR
------------------------------
I was able to solve this by flipping the logic between the "and" statement. I also realized that I only wanted to display completed or voided records if I was logged in as the admin. What I have below works.
var text roles = ToText(UserRoles("ID"));
If (
// Is completed or voided
([Stage] = "Completed"
or
[Voided] = true)
and
// Role with ID 12 == "Administrator"
(Left($roles,3) = "12 " or
Contains($roles,"; 12 ;") or
Right($roles,3) = " 12" or
(Contains($roles,"12") and Length($roles) = 2))
or
// Role with ID 22 == "Solutions Champion"
(Left($roles,3) = "22 " or
Contains($roles,"; 22 ;") or
Right($roles,3) = " 22" or
(Contains($roles,"22") and Length($roles) = 2))
,
// If true, the button should display
URLRoot() & "db/" & [_DBID_TASK_ITEM_DETAILS] & "?a=API_GenAddRecordForm&_fid_11=" & URLEncode ([Record ID#])& "&z=" & Rurl()
,
// Is not completed or not voided
// Show button regardless of role
([Stage] <> "Completed" and [Voided] <> true)
,
// If true, the button should display
URLRoot() & "db/" & [_DBID_TASK_ITEM_DETAILS] & "?a=API_GenAddRecordForm&_fid_11=" & URLEncode ([Record ID#])& "&z=" & Rurl()
)