[D365] Client Script - Updating Label of Field
This will guide how to change label of field defending on certain field value.
[Task]
* The target country was changed from UK to US because sample data is based on US
* Label name changed as "ZIPP/.." to distingush label from the default label value
[Tips]
- Field control in collection fields can be only effective when calling it with "_composite_compositionLinkControl_"
ex) Collection: address1_composite
Control link: _compositionLinkControl_
Field(logical name): address1_postalcode
--> address1_composite_compositionLinkControl_address1_postalcode
- To change the label, use
formContext.getControl("name of control").setLabel("new name")
[Code]
this.formOnLoad = function(executeContext)
{
var formContext = executeContext.getFormContext();
formContext.ui.setFormNotification("Test version 2", "INFO", "UniqueID20240109-J")
if(formContext.getAttribute("address1_country").getValue() == null)
{
// country? null --> ZIPP/Postal Code
formContext.getControl("address1_composite_compositionLinkControl_address1_postalcode").setLabel("ZIPP/Postal Code")
}
else if(formContext.getAttribute("address1_country").getValue() == "U.S.")
{
// country? US --> Zip Code
formContext.getControl("address1_composite_compositionLinkControl_address1_postalcode").setLabel("Zip Code")
}
else
{
// country? NOT US --> Postal Code
formContext.getControl("address1_composite_compositionLinkControl_address1_postalcode").setLabel("Postal Code")
}
}
this.formOnChange = function(executeContext)
{
var formContext = executeContext.getFormContext();
formContext.ui.setFormNotification("Test version 2", "INFO", "UniqueID20240109-J")
if(formContext.getAttribute("address1_country").getValue() == null)
{
// country? null --> ZIPP/Postal Code
formContext.getControl("address1_composite_compositionLinkControl_address1_postalcode").setLabel("ZIPP/Postal Code")
}
else if(formContext.getAttribute("address1_country").getValue() == "U.S.")
{
// country? US --> Zip Code
formContext.getControl("address1_composite_compositionLinkControl_address1_postalcode").setLabel("Zip Code")
}
else
{
// country? NOT US --> Postal Code
formContext.getControl("address1_composite_compositionLinkControl_address1_postalcode").setLabel("Postal Code")
}
}
[Test]
1. Go to PowerApp site, https://make.powerapps.com/ then select "Apps" > "Accounts"
2. Select an account randomly
3. Check the notification and current label of "ZIP/Postal Code"
4. Input "Country/Region" filed as "U.S." then "Save"
5. Confirm that "ZIPP/Postal Code" has been changed to "Zip Code"