Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Ui Builder script get the user group

Dolev Peretz
Tera Contributor

hi

i work on ui builder and i need to check if the current user is part of specific group how i can get the group of my user in ui builder script? Screenshot 2024-07-21 160208.png

2 REPLIES 2

Akash4
Kilo Sage

Hello Dolev,

You can start with the following script and modify according to record names and your requirement:

function evaluateProperty({api, helpers}) {
        const userID = api.user.userID;
        const grpCheck = await fetch(`/api/<your namespace>/<group_check_page>?sys_id=${userID}`); 
 //if not sys_user_group, try with other tables partaining to your UI Builder pages
        const grpData = await grpCheck.json(); //data returns JSON with isMember key-value pair
        if (grpData.isMember) {
            return 'User is available or member of group';
        }
}

Hope this helps!
Regards, Akash
_____________________________________________________________________________
Please mark it as helpful👍 or Accept Solution✔️ based on the response to your query.

Regards, Akash
If my response proves useful, please mark it "Accept as Solution" and "Helpful". This action benefits both the community and me.

nicolastarr
Tera Contributor

Hi im kinda late.

But u can use a data source  of a data broker.