Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 general forum
Answered

Locking Field on same Field change

Posted on by 7,314

Hi,

I have tried many different ways to implement this but I am unable to achieve desired result. Please guide me if you have come across this with a good solution.

I have form with two options field. I am trying to lock this two options field once the user makes a choice and saves the form. That means he has locked his choice.

So, far I tried a business rule and a client side script to lock the field on change of the same field. What's happening is it locks as soon as I click on the field and even before saving the form. That means if user makes a choice by mistake he can't revert back. And I can't implement it through plugin either. So, I am kind of stuck as to how best to implement this! Am I thinking through in the right direction? or is there a better way to handle this usecase? Please suggest.

Thanks for any help!

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Locking Field on same Field change

    Hi,

    You can replace the On Change event with the On Save event. If you want to add the On Save event, you can click on the entire form instead of a specific field:

    pastedimage1626663834860v1.jpeg

    Add On save event:

    pastedimage1626663858341v2.jpeg

    JavaScript Code:

     

    function disableField(executionContext){
    
                    var formContext = executionContext.getFormContext();
    
                    formContext.getControl("frank123_duration").setDisabled(true);
    
    }

    Before saving:

    pastedimage1626663935586v3.jpeg

    After saving:

    pastedimage1626663954309v4.jpeg

  • Suggested answer
    Hari Narayanan Profile Picture
    Hari Narayanan 589 on at
    RE: Locking Field on same Field change

    Hi,

    if the field type is two options, that means there is always a default value set (either 1 or 0), so your requirement is like a check box, where when user set it to Yes and save then never allow users to uncheck.

    If my above understanding is correct, then you must make the field read-only on onload of the form by following condition

    if(formtype ==2)//updateform

    {

       if(myfieldValue == 1)

        {

           setDisable the field here;

        }

    }.

    If event is set on onchange of the field, then users may not be able to make change. so the field should be set disable on onload.

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

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

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

#2
Martin Dráb Profile Picture

Martin Dráb 228,588 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans