Welcome to the nuBuilder Forums!

Register and log in to access exclusive forums and content available only to registered users.

Select all records if the logged in user is a global admin or only user records if not a globaladmin Topic is solved

Questions related to customising nuBuilder Forte with JavaScript or PHP.
Post Reply
TitanCompMan
Posts: 4
Joined: Wed May 03, 2023 6:15 pm
Has thanked: 2 times

Select all records if the logged in user is a global admin or only user records if not a globaladmin

Unread post by TitanCompMan »

I'm using this SQL code in Browse for an Inventories form. How do I modify it to show all inventories if the logged in user is a global admin? Right now this just code just shows the records where the userid matches the logged in user.

Code: Select all

SELECT inventories.userid,
       inventories.inv_site,
       inventories.invroomid,
       inventories.yearsid,
       inventories.gradesid,
       zzzzsys_user.zzzzsys_user_id,
       sites.sites_id,
       rooms.roomsid,
       schoolyears.yearsid,
       grades.*
FROM inventories
JOIN zzzzsys_user ON inventories.userid = zzzzsys_user.zzzzsys_user_id
JOIN sites ON inventories.inv_site = sites.sites_id
JOIN rooms ON rooms.roomsid = inventories.invroomid
JOIN schoolyears ON inventories.yearsid = schoolyears.yearsid
JOIN grades ON inventories.gradesid = grades.grades_id
WHERE inventories.userid = '#USER_ID#'

Can I use some kind of Case statement in the Where field?

Code: Select all

WHERE 
    CASE 
        WHEN ????  = 'globaladmin' THEN ?????  -- Select all records for globaladmin
        ELSE inventories.userid = '#USER_ID#'  -- Select records for a specific user
    END
kev1n
nuBuilder Team
Posts: 4292
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 444 times
Contact:

Re: Select all records if the logged in user is a global admin or only user records if not a globaladmin

Unread post by kev1n »

Hi,

Try:

Code: Select all

WHERE inventories.userid = '#USER_ID#' OR '#GLOBAL_ACCESS#' = '1'
TitanCompMan
Posts: 4
Joined: Wed May 03, 2023 6:15 pm
Has thanked: 2 times

Re: Select all records if the logged in user is a global admin or only user records if not a globaladmin

Unread post by TitanCompMan »

kev1n wrote: Thu Jan 25, 2024 5:54 pm Hi,

Try:

Code: Select all

WHERE inventories.userid = '#USER_ID#' OR '#GLOBAL_ACCESS#' = '1'
That worked!!!
Post Reply