Hello David,
In addition of my comment (https://forum.plantuml.net/11402/function-result-generating-a-syntax-error?show=11409#c11409), with :
- Use of Procedure (see green color)
- Boolean management (for INCLUDE_DESC see violet color, for $id_exist see blue color)
We obtain:
@startuml
!unquoted procedure $app($id)
!includeurl https://raw.githubusercontent.com/RicardoNiepel/C4-PlantUML/release/1-0/C4_Container.puml
!$data={"participants" :[
{"id": "cm" ,"label": "customer master","desc": "manages customers"},
{"id": "tm" ,"label": "transaction manager","desc": "manages transactions"},
{"id": "am" ,"label": "account master","desc": "manages accounts"}
]
}
!$id_exist = %false()
!foreach $part in $data.participants
!if $part.id == $id
!$id_exist = %true()
!if $INCLUDE_DESC
System($part.id, $part.label, $part.desc)
!else
System($part.id, $part.label)
!endif
!endif
!endfor
!if %not($id_exist)
System($id, "enter label for <u:red>$id")
!endif
!endprocedure
!includeurl https://raw.githubusercontent.com/RicardoNiepel/C4-PlantUML/release/1-0/C4_Container.puml
%set_variable_value("$INCLUDE_DESC", %true())
System(aa, "aa system")
System(bb, "bb system", "big system")
$app(tm)
$app(am)
$app(Xm)
@enduml

[Click on the image to view code]
If that can help,
Regards,
Th.