Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX (Archived)

Setting form to view (not edit) mode in code

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

In brief, I have a form which normally opens up in edit mode.

Under certain circumstances (if a certain field is true), I want the form to open in view (not edit) mode.

Do I need to add code to the init method on the form, or the active method on the datasource? In either case, how do I programmatically toggle between edit and view mode? Also, how do I programmatically know if I am currently viewing or editing a record?

Thanks for any assistance,

Bill Yater

Blue Horseshoe Solutions, Inc

*This post is locked for comments

  • Suggested answer
    Yev Profile Picture
    Yev 35 on at
    RE: Setting form to view (not edit) mode in code

    call the following code to switch to edit mode from X++:

    element.task(4471);

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Setting form to view (not edit) mode in code

    Fh-inway,

    Thank you for your help. I went to the AXBlogger article in your link, and found the element.inViewMode() statement.

    That did the trick in letting me detect if I was in View or Edit mode.

    I was even able to use that in my Edit button's clicked method, so I can do some pre-editing checks if they are currently in View Mode and about to edit a record.

    My form does only show one record at a time.

    I also tried to add the following code to my form's init method:

       if (my condition check return true)

       {

               //  Set the form to view mode

               element.design().viewEditMode(ViewEditMode::View);

       }

    This does set the form to view mode, but then I can't ever edit the record shown, even when I click the Edit button.

    I'm sure I'm not the only person who has to programmatically switch between View and Edit mode at runtime.

    Any other thoughts?

    Bill Yater

    Blue Horseshoe Solutions, Inc

  • Verified answer
    Florian Hopfner Profile Picture
    Florian Hopfner 2,449 on at
    RE: Setting form to view (not edit) mode in code

    ViewEditMode is a property of the form design. If your form displays only one record, you should use the init method. If it shows several records and the ViewEditMode should change depending on the selected record, you should use the active method. You can use element.inViewMode() to determine if you are in view mode.

    See also http://axbloggerblog.blogspot.de/2012/07/ax-2012-view-and-edit-mode.html

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,445 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans