web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id : Xxiov+97TPaIPlXFhHEHFt
Power Apps - Microsoft Dataverse
Unanswered

Can't Lock two same field in one form using javascript

Like (0) ShareShare
ReportReport
Posted on 13 Apr 2022 03:30:48 by 2

I have a form that contain two same fields 'Nama Mentor PIC' with logical name 'ecom_namamentor'

I want to lock them using javascript, but when I run the application only 1 field is locked while the others are not.
even though both fields have the same logical name, and in javascript I have set it to be locked but it doesn't work.
how can i lock those two fields? Did I miss something?

 

this is javascript code

Screenshot 2022-04-13 102553.png

 

and this is what the form field looks like when javascript is run

WhatsApp Image 2022-04-13 at 10.23.24.jpeg

I have the same question (0)
  • Mira Ghaly Profile Picture
    11,409 Moderator on 13 Apr 2022 at 04:51:39
    Re: Can't Lock two same field in one form using javascript

    @DewiCR 

    Please use the below and remember to pass executionContext as the first Parameter when registering the event

    var formContext = executionContext.getFormContext();
    
    var attr = formContext.getAttribute("ecom_namamentor");
    attr.controls.forEach(function (control) {
    control.setDisabled(true);
    });

     

  • EricRegnier Profile Picture
    8,716 Most Valuable Professional on 14 Apr 2022 at 09:31:48
    Re: Can't Lock two same field in one form using javascript

    Hi @DewiCR,

    To supplement on @Mira_Ghaly post, the controls.get gets the first control but since you have more than 1 on the form that's why you would have to loop through each one as per the sample code. And Xrm.Page is deprecated so this is why the code uses formContext. Hope her post helps!

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Chiara Carbone – Community Spotlight

We are honored to recognize Chiara Carbone as our Community Spotlight for November…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 714 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 419 Super User 2025 Season 2

#3
developerAJ Profile Picture

developerAJ 243

Last 30 days Overall leaderboard

Featured topics

Loading complete