I generate a string out of elements in a gallery, each element may or may not be blank and may or maynot differ from two versions based on input from a form.
The current and obviously not best way to deal with this is:
Left(
Trim(
Concat(
[
Text(
If(
IsBlank(ThisItem.Patch.INST_NO),
ThisItem.Original.INST_NO,
ThisItem.Patch.INST_NO
)
),
Text(
If(
IsBlank(ThisItem.Patch.NOM_DIAM),
ThisItem.Original.NOM_DIAM,
ThisItem.Patch.NOM_DIAM
)
),
Text(
If(
IsBlank(ThisItem.Patch.TAG),
ThisItem.Original.TAG,
ThisItem.Patch.TAG
)
),
Text(
If(
IsBlank(ThisItem.Patch.PIPING_CLASS),
ThisItem.Original.PIPING_CLASS,
ThisItem.Patch.PIPING_CLASS
)
),
Text(
If(
IsBlank(ThisItem.Patch.INSULATION_CLASS),
ThisItem.Original.INSULATION_CLASS,
ThisItem.Patch.INSULATION_CLASS
)
)
],
If(
IsBlank(Value),
"",
Value & "-"
)
)
),
Len(
Trim(
Concat(
[
Text(
If(
IsBlank(ThisItem.Patch.INST_NO),
ThisItem.Original.INST_NO,
ThisItem.Patch.INST_NO
)
),
Text(
If(
IsBlank(ThisItem.Patch.NOM_DIAM),
ThisItem.Original.NOM_DIAM,
ThisItem.Patch.NOM_DIAM
)
),
Text(
If(
IsBlank(ThisItem.Patch.TAG),
ThisItem.Original.TAG,
ThisItem.Patch.TAG
)
),
Text(
If(
IsBlank(ThisItem.Patch.PIPING_CLASS),
ThisItem.Original.PIPING_CLASS,
ThisItem.Patch.PIPING_CLASS
)
),
Text(
If(
IsBlank(ThisItem.Patch.INSULATION_CLASS),
ThisItem.Original.INSULATION_CLASS,
ThisItem.Patch.INSULATION_CLASS
)
)
],
If(
IsBlank(Value),
"",
Value & "-"
)
)
)
) - 1
)
This is such a mess, there must be a better way to deal with it. I have some experience with imperative languages, but I'm struggelig to keep the code "DRY" because I really have a hard time to wrap my head around certain declarative concepts. Whenever I create tiny ripples of complexity, they become tidalwaves further down the line causing the simplest functions hard to use; like in this case where i just want to join all elements with a "-" between each element.
Suggestions would be greatly appreciated! 🙂