Getting the list of Teams Assigned to the Current User

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Triggerz
    Member
    • May 2024
    • 64

    Getting the list of Teams Assigned to the Current User

    Hi,

    I am trying to get the list of Teams assigned to the current user. I tried the code below in the Formula Sandbox but I am getting an Error 500.
    I need this to check if a user is assigned to a specific team and use this as a condition to make fields read-only. Please help.

    output\printLine(env\userAttribute('teams'));


    Thanks
  • victor
    Active Community Member
    • Aug 2022
    • 799

    #2
    Code:
    $userTeamsNames = env\userAttribute('teamsNames');
    output\printLine($userTeamsNames);
    Click image for larger version

Name:	image.png
Views:	0
Size:	44.6 KB
ID:	115414

    Comment

    • Triggerz
      Member
      • May 2024
      • 64

      #3
      Hi victor,

      Thank you so much, the code you provided works perfectly.

      I also need to get the role names, I tried executing the code below but I am getting a {} output. Not sure if I have the wrong parameter, please help as well on this please.

      Code:
      $userRolesNames = env\userAttribute('rolesNames');
      output\printLine($userRolesNames);
      Thanks

      Comment

      • victor
        Active Community Member
        • Aug 2022
        • 799

        #4
        Click image for larger version

Name:	image.png
Views:	0
Size:	49.3 KB
ID:	115427
        Code:
        $i = 0;
        
        while ($i < array\length(rolesIds)) {
        
        $roleId = array\at(rolesIds, $i);
        $roleName = record\attribute('Role', $roleId, 'name');
        
        $rolesNames = array\push($rolesNames, $roleName);
        
        $i = $i + 1;
        }
        
        output\printLine($rolesNames);​
        Please note that now you must select the User whose role you want to receive.

        You can modify this formula a bit and apply it to teams:

        Click image for larger version

Name:	image.png
Views:	0
Size:	44.8 KB
ID:	115428
        Code:
        $i = 0;
        
        while ($i < array\length(teamsIds)) {
        
        $teamId = array\at(teamsIds, $i);
        $teamName = record\attribute('Team', $teamId, 'name');
        
        $teamsNames = array\push($teamsNames, $teamName);
        
        $i = $i + 1;
        }
        
        output\printLine($teamsNames);​

        Comment

        Working...