Hi, I need to get the current security role that controls the current table
example :
"Social Table" exist on "Social Salary Role"
I need x++ code to show the "Social Salary Role" when the user open the "Social Table"
select securityRole
join securityUserRole
where securityUserRole.SecurityRole == securityRole.RecId
join userInfo
where userInfo.id == securityUserRole.User
&& userInfo.id == curUserId()
this code get all role that associate with current user
what condition I have to add to select the only active role
First of all, you're not opening tables, you're opening forms.
Forms are opened by menu items, which are linked to privileges. And you can find the related roles by using the SystemSecurityPermissionEntity like I mentioned in my very first reply. This entity also contains the related security role.
Then you can use SystemSecurityUserRoleEntity to find the roles of any (also current) user.
I'm sorry but I don't think that I can provide any more help than I did in my first message. I hope you can find the solution by going through the already provided information one more time.
No,
("Social Table" exist on "Social Salary Role")
I need this information from the code.
when I open Any Table I want this Information
"Which role is associated with the table I opened"
Sorry, I don't understand.
Or do you just mean how to get the selected role (record) in the "Assign users to roles" form? So is your question: "how to get the selected record from the current form's data source"?
"Social Table" exist on "Social Salary Role"
- pay group 'A' assigned to "Social Salary Role"
- pay group 'B' assigned to "system user"
when I open "Social Table" it fetches the record that has
A & B pay group it's supposed to fetch only record that
has 'A' pay group only
"Social Table" is the current table
and "Social Salary Role" is the current table role
Hi,
and what do you mean by "current table role"?
sorry again let start from the beginning
I need to create a Button Assign Pay group like
Assign organization (Standard from Microsoft)
everything works fine with the new button but it fetches
all pay groups from all roles, I need the select statement to fetch only the pay group that is associated with the current table role.
Hi,
there's no function that would return "current role" of the user. And there can't be - the user can have (and usually must have) multiple role assigned (System user role is mandatory, and usually they have also other roles assigned).
I think you might need to go back to your actual business requirement and start again from there. And if you need help, don't hesitate to share the business requirement with us. Thanks!
I apologize for the lack of clarity. The code works, but it gives the same results as before. I need to know the "RecId" for the role currently in use
is there a code
like curExt() or curUserId()
but for the avtice Role
I use this code on security policy to filter data so I need to know which role run this class
Hi Oadiba,
I don't know what your code is supposed to do. Or if you have something else before this code.
But let's take a look at the code that you shared.
When you debug it, you will notice that SystemSecurityPermissionEntity.SecurityRoleName is empty because you haven't selected anything from SystemSecurityPermissionEntity.
So your code is asking for all SecurityRole records where SecurityRole.Name is empty. Therefore it's not returning anything.
If you need support in writing select statements and joins , I suggest to start here: https://docs.microsoft.com/en-us/dynamicsax-2012/developer/select-statements (including the other pages that it links to). But once you're familiar with select statements, you will find the data that you're looking for by using the entities that I mentioned.
Hi, thanks for the reply,
I tried this code but it doesn't work :
select firstonly securityRole
where SystemSecurityPermissionEntity.SecurityRoleName == securityRole.name
join securityUserRole
where securityUserRole.SecurityRole == securityRole.RecId
join userInfo
where userInfo.id == securityUserRole.User
&& userInfo.id == curUserId()
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 290,802 Super User 2024 Season 2
Martin Dráb 229,133 Most Valuable Professional
nmaenpaa 101,154