Programmatically determine if user linked to a role

irenegireneg Member Posts: 30
Hi there

Navision security: I need to determine if a user is linked to a specific role. Is there a command that can do this?

Thanks
Irene Grassow

Answers

  • DaveTDaveT Member Posts: 1,039
    Hi

    Do a lookup to the "Member Of" table 2000000003
    Dave Treanor

    Dynamics Nav Add-ons
    http://www.simplydynamics.ie/Addons.html
  • AlbertvhAlbertvh Member Posts: 516
    Hi

    You could use the "Member of" (2000000003) table and set a range on the user and role id to see if the user exist for that role.

    Hope this helps

    Albert
  • kinekine Member Posts: 12,562
    It is not so easy, because you need to count with two cases:

    DB User
    Windows User

    and the second one means that you can be member of group which is member of the role... ;-)
    IsMemberOf(UserIDVal : Code[20];RoleID : Code[20]) : Boolean
    Var
      MemberOf : Record 2000000003
    begin
      IF MemberOf.GET(UserIDVal,RoleID) THEN
         EXIT(TRUE);
      
      EXIT(IsWinMemberOf(UserIDVal,RoleID));
    end;
    
    IsWinMemberOf(UserIDVal : Code[20];RoleID : Code[20]) : Boolean
    Var
      Domain : Record 2000000056
      WinMemberOf : Record 2000000053
    begin
      IF Domain.FIND('-') THEN
      REPEAT
        IF WinMemberOf.GET(Domain.SID,RoleID,'') THEN
          EXIT(TRUE);
      UNTIL Domain.NEXT=0;
    
      EXIT(FALSE);
    end;
    

    You can use the IsMemberOf function with UserID and RoleID to detect if the user is member of the role, BUT this function works correctly only if the UserID is the ID of the logged in user or ID of some Database User. If you enter ID of another windows user, it will not work correctly, because the virtual tables used in IsWinMemberOf are filled just with records for the logged in Windows User.
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • krikikriki Member, Moderator Posts: 9,110
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


Sign In or Register to comment.