Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Apps - Microsoft Dataverse
Answered

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

Categories:
  • EBMRay Profile Picture
    1,710 on at
    Re: Model-Driven / Set field label programmticaly

    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!

  • Verified answer
    Parvez Ghumra Profile Picture
    1,579 Super User 2025 Season 1 on at
    Re: Model-Driven / Set field label programmticaly

    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

  • Verified answer
    Mira Ghaly Profile Picture
    11,409 Super User 2025 Season 1 on at
    Re: Model-Driven / Set field label programmticaly

    @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
    a33ik Profile Picture
    3,304 Most Valuable Professional on at
    Re: Model-Driven / Set field label programmticaly

    Hello,

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

  • Verified answer
    Guido Preite Profile Picture
    1,488 Super User 2024 Season 1 on at
    Re: Model-Driven / Set field label programmticaly

    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?

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Power Apps - Microsoft Dataverse

#1
mmbr1606 Profile Picture

mmbr1606 22 Super User 2025 Season 1

#2
stampcoin Profile Picture

stampcoin 17

#3
ankit_singhal Profile Picture

ankit_singhal 11 Super User 2025 Season 1

Overall leaderboard

Featured topics