Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Answered

Controlling Security when opening a form through a FormRun object

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

I am currently opening a form through a button with the following code:

pastedimage1598982785043v2.png

The opened form is simply inheriting the security access from my caller form. For example, if user 1 has delete access to the current form A, clicks a button which opens form B, the user seems to inherit the delete access from A and is able to delete records on form B as well.

I would like to control the security here with more granularity - A and B should be able to have differing security between the two. One option is to modify this code to open through a Menu Item. This then separates the security between a caller and called form but will likely be a more invasive change for me to make.

Is there a way to accomplish separate security access levels while still using a FormRun object?

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Controlling Security when opening a form through a FormRun object

    I have tried to change the datasource property to AllowDelete = true, but this still doesn't enable the delete button if the security permission of the calling form has just Create access. The delete button seems to be disabled no matter what code I write to override it in this scenario. I think the only option for this is a MenuFunction.

  • Verified answer
    nmaenpaa Profile Picture
    nmaenpaa 101,156 on at
    RE: Controlling Security when opening a form through a FormRun object

    I think it's better to try to use MenuFunction, but there are some cases where it might not be possible.

    In such case, you can still check what kind of access the current user would have to the form's menu item. And based on that, you can change the data source properties AllowEdit, AllowCreate etc in code.

    www.schweda.net/blog_ax.php

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Controlling Security when opening a form through a FormRun object

    I tried giving explicit delete table permission for my lines form but that did not work, it seems to always want to take the caller forms security access in this situation. I think my only option is to refactor this to use a MenuFunction like you mentioned. Thanks!

  • Verified answer
    André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 291,711 Super User 2024 Season 2 on at
    RE: Controlling Security when opening a form through a FormRun object

    Hi Ryne,

    If the forms are using different tables, you can try to set different table permissions on the privilege or security role.

    It is also possible to call menu items using x logic. Then you can replace the FormRun with e.g. :

       MenuFunction    menuFunction;
       Args            args = new Args();
    
       args.record(RecordToPass);
    
       menuFunction = new MenuFunction(menuitemDispayStr(MenuItem), MenuItemType::Display);
    
       if (menuFunction && menuFunction.checkAccessRights())
       {
           menuFunction.run(args);
       }

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Controlling Security when opening a form through a FormRun object

    Hi Andre. The code to open the form like this has existed for a long time so I am unsure of the reasons it was written like this initially. The tables are custom on both forms. The calling form is a header form and hitting the button opens up a lines form. The business requirement is to now have a user with create access on the header form but delete access on the lines form. The FormRun seems to only consider the security of the calling form though, and opens the lines form with only create access as well - no matter what security it has for the lines table.

    The button can potentially open up a few different line forms so it would be much easier if I could control the security on a FormRun rather than having to restructure this to use Menu Items. Do you know if it is possible to do that?

  • André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 291,711 Super User 2024 Season 2 on at
    RE: Controlling Security when opening a form through a FormRun object

    Hi Ryne,

    Can you tell what datasources/tables are used on both forms? What is the reason that you open a form by coding on a button and not the menu item?

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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,711 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,458 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans