Skip to main content

Notifications

Dynamics 365 general forum
Suggested answer

Make a field enabled only on create, and read-only in other states

Posted on by 37

in an entity ive set a Max Students Number field, i need to make it editable only when creating the form, and make it read-only right after saving the form

how to do that?

when i set the field as read-only i cant edit it at all when creating a new form, i need to be able to set a value to it on create - then change it to read-only

i saw setsubmitmode but did not understand how to use it 

here's what im stuck at so far in writing the function thats supposed to do it: (if possible without code id wish to know as well)

function disableFieldOnSave(Context)
{
    var formContext = Context.getFormContext();
    var maxStudentsNumberField = formContext.getAttribute("opu_maxstudentsnumber").getValue();
}
  • Suggested answer
    RE: Make a field enabled only on create, and read-only in other states

    Hello,

    I hope you are doing well.

    Also is possible to use security profile of fields such as docs.microsoft.com/.../field-level-security.

    In this situation is ensured that user can't change your rule, based on JavaScript can be changed on DEVTools on browser.

    Kind Regards,

  • Suggested answer
    JyotiYadav Profile Picture
    JyotiYadav 40 on at
    RE: Make a field enabled only on create, and read-only in other states

    Hi,

    You need to check the formtype using formContext.ui.getFormType(). docs.microsoft.com/.../getformtype

    If formtype  value is 1 i.e Create, you can enable the field formContext.ui.controls.get("your field name").setDisabled (false);

    else you can disable your field formContext.ui.controls.get("your field name").setDisabled (true); .


    Please mark as verified if the answer is useful.

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Make a field enabled only on create, and read-only in other states

    Hi,

    As MicroDynamicalCRM said, you can use getFormType to get the form type, you can refer to the following official documents:

    getFormType (Client API reference) in model-driven apps - Power Apps | Microsoft Docs

    pastedimage1631580769326v1.png

    If this helped you, I'd appreciate it if you'd mark this as a Verified Answer, which may in turn help others as well.

    Best Regards,

    Frank Gong

  • Suggested answer
    RE: Make a field enabled only on create, and read-only in other states

    Update Edit:

    i've just read about GetFormType()

    now i know what to do:

    get the form type and setDisabled to false when the formtype value is "create" , and true elsewhere.

    problem solved

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

Dynamics 365 Community Update – Sep 16th

Welcome to the next edition of the Community Platform Update. This is a weekly…

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,522 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,441 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans