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 / Model-Driven / Set fie...
Power Apps
Unanswered

Model-Driven / Set field label programmticaly

(0) ShareShare
ReportReport
Posted on by 1,710

Hello,

I would like to set the field text label dynamically according to a selected value from a lookup field.

Example: If I selected the BU Unit Type: Department, the Business Unit label should be renamed to Department.

Julien2_0-1689604656357.png

 

I have tried to follow the below documentation. However, it is not working as expected and nothing happens.

https://learn.microsoft.com/en-us/power-apps/developer/model-driven-apps/clientapi/reference/controls/setlabel

Below is the code:

 

 

function onLoadGetBUType (executionContext){

 var formContext = executionContext.getFormContext();

 if(formContext.getAttribute("hrex2193_businessunittype").getValue() != null) {

 var temp = formContext.getAttribute("hrex2193_businessunittype").getValue()[0].name;

 // console.log(temp);

 formContext.ui.controls.get("hrex2193_adepartmenta").setLabel(temp);

 formContext.getControl("hrex2193_adepartmenta").setLabel(temp);

 }

}

 

 

Is there a way to set the field label programmatically?

Any help is greatly appreciated.

Best regards,

Julien

I have the same question (0)
  • Verified answer
    Guido Preite Profile Picture
    1,488 Super User 2024 Season 1 on at

    the code looks correct (these two lines do exactly the same thing, the second is the usual one):

    formContext.ui.controls.get("hrex2193_adepartmenta").setLabel(temp);
    formContext.getControl("hrex2193_adepartmenta").setLabel(temp);

    inside the console do you get the correct value of temp? do you get some expections?

  • Verified answer
    a33ik Profile Picture
    3,306 Most Valuable Professional on at

    Hello,

    Is there a chance that you have placed the field hrex2193_adepartmenta twice on the form?

  • Verified answer
    Mira Ghaly Profile Picture
    11,413 Moderator on at

    @Julien2 

    As @a33ik mentioned if the field is placed twice on the form it might be the issue.

    Have you registered this on the onload as well as on the onchange of the lookup?

    I think the best way to troubleshoot this is by debugging.

     

  • Verified answer
    Parvez Ghumra Profile Picture
    1,579 Moderator on at

    Hi @Julien2 ,

     

    I'd definitely recommend debugging your script using the browser's developer tools. Also double check that you're using the correct column names for each control/attribute referenced in the script

  • EBMRay Profile Picture
    1,710 on at

    Hello everyone,

     

    Thank you for your support.

     

    After our investigation, the fields are placed in the "Header" of the form and what we've learned is that the logical name of the fields starts with "header_LogicalFieldName". We used the same code and it worked perfectly after adjustment of the fields' logical names in the code.

     

    Thank you!

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 796 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 327 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard