Security to push button in Vendor Card

souravbsouravb Member Posts: 135
Hi,
I was trying to use authorization in a way that people who dont have the SUPER role will not be allowed to calculate the vendor score in the Cal Score pushbutton of Vendor menu item. I wrote a code like this:

GVMemberOf = Record of Member Of Table

GVMemberOf.SETRANGE(GVMemberOf."User ID",USERID);
IF GVMemberOf.FIND('-') THEN
GVMemberOf.SETFILTER(GVMemberOf."Role ID",'<>SUPER');
IF GVMemberOf.FIND('-') THEN
ERROR('ABCD');

CalcRoutineCall.

But the code doesn't have any effect. Plz help me how to do it.

Comments

  • Luc_VanDyckLuc_VanDyck Member, Moderator, Administrator Posts: 3,633
    Try this:
    GVMemberOf.SETRANGE(GVMemberOf."User ID",USERID); 
    GVMemberOf.SETRANGE(GVMemberOf."Role ID",'SUPER'); 
    IF NOT(GVMemberOf.FINDFIRST) THEN 
      ERROR('ABCD');
    
    No support using PM or e-mail - Please use this forum. BC TechDays 2024: 13 & 14 June 2024, Antwerp (Belgium)
  • jonsan21jonsan21 Member Posts: 118
    Hi,

    Don't forget to filter by the Company Name though.

    Rgds,

    Jon.
    Rgds,

    Jon.
  • babbab Member Posts: 65
    Hi,
    and if you are using windows authentication don't forget the Windows Access Control table either...
    I mean you can create a function HasRole(RoleName: Code[20]): Boolean like this:
    MemberOf.RESET;
    MemberOf.SETRANGE("User ID", UPPERCASE(USERID));
    MemberOf.SETRANGE("Role Name", RoleName);
    IF MemberOf.FINDFIRST THEN
      EXIT(TRUE);
    WinAccControl.RESET;
    WinAccControl.SETRANGE("Role ID", RoleName);
    WinAccControl.SETFILTER("Login ID", '*\' + USERID);
    EXIT(WinAccControl.FINDFIRST);
    
  • kinekine Member Posts: 12,562
    And if you are using Windows authentication, do not forget to search for all AD groups which is the user member of. :-) Using windows authentication correctly is not easy... :wink:
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
Sign In or Register to comment.