Function UserBelongsToRoleInCompany(ItxtUserID:text250 ; IcodRoleID:Code20 ; ItxtCompany:Text30): Boolean // Checks if a user belongs to a certain role in a certain company // PARAMETERS: // ItxtUserID:user to check (mostly USERID) // IcodRoleID:the role ID to check (can also be 'SUPER') // ItxtCompany:Company to check (mostly COMPANYNAME) // RETURN-VALUE:TRUE : user belongs to the role in the company ; FALSE:user doesn't belong to the role in the company // local variables : // LrecMemberOf : record of table 2000000003 // LrecWindowsAccessControl : record of table 2000000053 LrecMemberOf.RESET; LrecMemberOf.SETCURRENTKEY("User ID","Role ID",Company); LrecMemberOf.SETRANGE("User ID",ItxtUserID); LrecMemberOf.SETRANGE("Role ID",IcodRoleID); LrecMemberOf.SETFILTER(Company,'%1|%2',ItxtCompany,''); IF LrecMemberOf.FIND('-') THEN EXIT(TRUE); LrecWindowsAccessControl.RESET; LrecWindowsAccessControl.SETCURRENTKEY("Login SID","Role ID","Company Name"); LrecWindowsAccessControl.SETRANGE("Login SID",ItxtUserID); LrecWindowsAccessControl.SETRANGE("Role ID",IcodRoleID); LrecWindowsAccessControl.SETFILTER("Company Name",'%1|%2',ItxtCompany,''); IF LrecWindowsAccessControl.FIND('-') THEN EXIT(TRUE); EXIT(FALSE);
Comments
You can also test windows groups and not only windows users. But if you use windows groups, the user you are testing MUST be the current user.
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!