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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Can't Lock two same fi...
Power Apps
Unanswered

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

(0) ShareShare
ReportReport
Posted on 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,413 Moderator on at

    @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,720 Most Valuable Professional on at

    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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 717 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 329 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard