To check if the current user has a specific role we will have to write the following code in the appropriate place as per the requirement.
UserInfo userInfo;
SecurityUserRole securityUserRole;
SecurityRole Roles;
boolean allowed;
select id from userInfo
join SecurityRole from securityUserRole
where securityUserRole.User == userInfo.Id
join Roles where Roles.RecId == securityUserRole.SecurityRole
&& (Roles.AotName =='ROLENAME')
&& UserInfo.id == curUserId();
if(UserInfo.id == curUserId())
{
Allowed = true;
}
Check out my previous blog: OData in Microsoft Dynamics 365 F&O
Need help? Connect Atul
Latest posts by Atul Yadav (see all)
- IP level security on Dynamics 365 F&O Dev Server using NSG - July 5, 2024
- Logic apps VS Power Automate flow - June 28, 2024
- Multithreading batch job in Microsoft Dynamics 365 Finance and Operations - June 21, 2024