Question
Sopra Steria
NL
Last activity: 12 Aug 2022 8:17 EDT
Pattern: using a parameter for label values
Sometimes, you want to show a property with a different label depending on where it is referenced. This can be done by using field values in different classes or rulesets or, or by using a visibility condition on the control with the label.
I though of another approach: we can also pass the label value as a parameter. But, I am using this cautiously, as it might open a whole box of bad reasons why we should avoid this. I'm curious if this design can be leveraged safely for a few use cases, or if there are good reasons why we should always choose a different approach.
Kind regards,
Bas
@BasRulesMatter
To me this is fine.
But I can think of two potential downsides.
1. Localization of that label will be more difficult.
But Pega still treats the parameter as a reference to a field value (if a field value exists for the parameter value it uses the field value, if no field value exists for the parameter value, it takes the parameter value as a string input), so you could still perform localization in that way, you just have to make sure that all potential values of that param always refer to a field value in the system, because the localization wizard will not call them out otherwise.
2. For reusability sake, if you want to have the same property in multiple sections, and give the property label a different value depending on the section that it is in, why not just define the label explicitly in each section instead of dynamically setting a param? That would be easier to understand for others using it as long as each section had a clearly defined purpose.
On the other hand, if your property has complex config on it (like multiple events and actions), then wrapping the property in a section and parameterising the key config (including label) will save time on maintainability if you have to make changes later. (some of the toolbar items in OOTB UI Kit, like the notification icon used to do this)