Skip to main content

Notifications

Announcements

No record found.

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

What is the best way to disable edit on form fields except 2 fields?

(0) ShareShare
ReportReport
Posted on by 896

Hello dear community :)

What is the best way to disable form fields except for 2 fields for example?

I've seen a loop through form objects disabling them while checking if the fieldsnumber() is equal to the exception fields but is there a better way for doing this?

Thanks in advance!!!

  • AJJAIS Profile Picture
    AJJAIS on at
    RE: What is the best way to disable edit on form fields except 2 fields?

    Hello,

    You can also try Personalization- Locked views as per https://docs.microsoft.com/en-us/dynamics365/fin-ops-core/fin-ops/get-started/saved-views?toc=/dynamics365/commerce/toc.json#switching-between-views. You can lock the required fields and user can not edit them. Please take a look. Thank you.

  • ergun sahin Profile Picture
    ergun sahin 8,812 Super User 2024 Season 1 on at
    RE: What is the best way to disable edit on form fields except 2 fields?

    Martin's answer is correct, but I must add something. I saw that the allowEditFieldsOnFormDS_W method called in the active method causes performance problems. If there is no requirement, you must call the method before the active (init etc).

  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 230,476 Most Valuable Professional on at
    RE: What is the best way to disable edit on form fields except 2 fields?

    Then you should iterate table fields rather than form controls and set AllowEdit of data source fields rather than form controls. It's easier, because table fields are not hierarchical, you don't have to deal with form controls that you're not interested in and changing the property of a data source field applies to all controls bound to this field.

    And you don't even have to do it by yourself - you can utilize a standard method called allowEditFieldsOnFormDS_W. For example:

    // Disable all data source fields
    allowEditFieldsOnFormDS_W(myTable_ds, false);
    
    // Enable fields you want
    myTable_ds.object(fieldNum(MyTable, MyField)).allowEdit(true);

  • Momochi Profile Picture
    Momochi 896 on at
    RE: What is the best way to disable edit on form fields except 2 fields?

    Hello Martin,

    Yes.

  • Martin Dráb Profile Picture
    Martin Dráb 230,476 Most Valuable Professional on at
    RE: What is the best way to disable edit on form fields except 2 fields?

    Are the controls bound to data source fields?

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,784 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,476 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans