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