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.
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
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!
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
Hello,
Is there a chance that you have placed the field hrex2193_adepartmenta twice on the form?
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?
mmbr1606
22
Super User 2025 Season 1
stampcoin
17
ankit_singhal
11
Super User 2025 Season 1