web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

How to open a form in Read and Delete access only based on roles via x++

(0) ShareShare
ReportReport
Posted on by

Hi All,

I have created a simple FORM with a data source and a grid in it.  The Grid shows just two fields.

I have two Roles namely "HcmHumanResourceAssistant" & "HcmHumanResourceManager".  

(1) So when an user with role "HcmHumanResourceAssistant" assigned opens the FORM then the it should be in read mode only. I mean the user should not be able to create , update or delete record.  Only he can read/view records.

(2) Similarly when an user with role "HcmHumanResourceManager" assigned opens the FORM then the it should be in delete mode only. I mean the user should not be able to create , update record.  Only he can delete/view records.

How could I have achieve this via x++ code. Please help !!

Regards,

Mania

*This post is locked for comments

I have the same question (0)
  • Verified answer
    nmaenpaa Profile Picture
    101,162 Moderator on at

    You can accomplish this with adding/modifying security privileges, and adjusting the form's properties.

    First, modify the form's data source, set AllowCreate to No and AllowEdit to No. Now the form doesn't let anyone create or edit records.

    Then, create two security privileges (or modify / extend some existing privileges):

        - One privilege for viewing the data on the form. In this privilege, add the menu item that opens your form to the Entry points node, and set access level to Read. Assign this privilege to HcmHumanResourceAssistant role (or assign it to a duty which is already assigned to this role).

        - One privilege for maintaining the data on the form. In this privilege, add the menu item that opens  your form to the Entry points node, and set access level to Delete. Assign this privilege to HcmHumanResourceManager role (or assign it to a duty which is already assigned to this role).

  • Verified answer
    Sukrut Parab Profile Picture
    71,710 Moderator on at

    HI Axmani ,

    You can achieve this using role based security , I am not sure why you want to use x++ code here. For HcmHumanResourceAssistant create a menu item of your form and give read only access . Just to make sure you understand delete mode , delete permission means everything . If you give delete permission then you users can create/update /delete.

    if you want to do it using x++ code then create these two roles assign users to these roles and then check in the code if user who is opening form belongs to any of these roles and based on that handle/allow creation /deletion /updating datasource of the form.

  • Community Member Profile Picture
    on at

    Hi Nikolaos,

    That works like charm.

    Just a clarification if an user is assigned with System Administration can perform any thing right ?

    Regards,

    Mania

  • Community Member Profile Picture
    on at

    Hi Sukrut ,

    Thanks for your reply.

    The reason I wanted to achieve this via x++ , if there are 50 people who might use this roles in many different branches then I have to assign each and every member to whom the roles belongs to.

    What if an user has System Administration rights?.  It means those roles even if added with the privileges as you have suggested will make not any sense or does not have any impact right ?.  I am sorry my Question is silly but still I wanted be sure if am correct ?

    Please reply.

    Thanks,

    Mania

  • Verified answer
    nmaenpaa Profile Picture
    101,162 Moderator on at

    Hi Mania,

    Even the system administrator can't create/edit records if it's restricted on the form data source.

    For this use case you would need to do some x++ development, because the standard capabilities of AX privileges will not fulfill your needs. With the privileges, if an user has right to delete records, he/she will always have the right to create/edit, too.

    In addition to my previous instructions, put following code in the form's init method:

    if (Global::isSystemAdministrator())
    {
        yourTable_ds.allowEdit(true);
        yourTable_ds.allowCreate(true);
    }


    Now the system administrator can create/edit records.

  • Community Member Profile Picture
    on at

    Hi Nikolaos,

    Both of your suggestions just worked as expected . Very very thankful to you.

    Regards,

    Mania

  • Community Member Profile Picture
    on at

    Hi Sukrut ,

    Thank you very much for your nice explanation. From this thread I have learnt a new thing . Thank you guys . Please keep up doing this good work in your leisure time

    Once Again Thank you Sukrut and Nikolaos.

    Regards,

    Mania

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans