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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Model-Driven / Set fie...
Power Apps
Answered

Model-Driven / Set field label programmticaly

(0) ShareShare
ReportReport
Posted on by 1,712

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,490 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,415 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,712 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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 640

#2
Vish WR Profile Picture

Vish WR 633

#3
Valantis Profile Picture

Valantis 548

Last 30 days Overall leaderboard