Hello David,
1/ First: We will test without redirection on a variable ($d)
and if you want to use 'unquoted', it is necessary to suppress the double-quote on the test :
!if $part.id == $id
Here is the first full example (and that is OK):
@startuml
!unquoted function $lookup($id)
!$data={"participants":[
{"id": "cm", "label": "label cm", "desc": "desc cm"},
{"id": "tm", "label": "label tm", "desc": "desc tm"},
{"id": "am", "label": "label am", "desc": "desc am"}
]}
!foreach $part in $data.participants
!if $part.id == $id
:id=$part.id \nlabel=$part.label \ndesc=$part.desc;
!endif;
!endfor
!endfunction
!$a="cm"
:$a;
$lookup($a)
$lookup(cm)
$lookup("cm")
'!$d=$lookup(cm)
@enduml
http://www.plantuml.com/plantuml/umla/RP1HReCm38RVVGedYhGXLJq0A5BliUt1YuDc3G8hoLF5tOS1iKxjatzz-CEnBrEcQovz1wQadpBaoDYM5B8C2Lqt3DzbV7N25HZ7bCdVxBW84cIab2TRly7D2jiQRUZj2Mr7dx6pzHvmWnode4ohelbqMFcPbH-j_C-YPnOzM8fc-9Z1jCCrKlX2fwz7IRXkSxxV1H2Dj5l7MHYzHoUyq5hO7_GzhSDsiEQ5wR0TQMpqNp6nj0reNQPlTRyiW77azM9GEshWE3HLHmxzNzRE2k35EFRttoynSUcxNm00
2/ Then: if you want a redirection on a variable ($d), perhaps it is necessary to use a return-function.
And if we add this :
!return ":id=$part.id \nlabel=$part.label \ndesc=$part.desc;"
We observe this defect: 500 - Internal Server Error
Here is the second full example, please unquote the line '!$d=$lookup(cm) :
@startuml
!unquoted function $lookup($id)
!$data={"participants":[
{"id": "cm", "label": "label cm", "desc": "desc cm"},
{"id": "tm", "label": "label tm", "desc": "desc tm"},
{"id": "am", "label": "label am", "desc": "desc am"}
]}
!foreach $part in $data.participants
!if $part.id == $id
!return ":id=$part.id \nlabel=$part.label \ndesc=$part.desc;"
!endif;
!endfor
!endfunction
:begin;
'!$d=$lookup(cm)
'$d
:end;
@enduml
Here is the link:
http://www.plantuml.com/plantuml/umla/RP1TReCm383VVGeJHUegLJq0A5BliUqXJS9cBIGCdAUgTvy3hDfKNh3vua_-kSni9ov3XAQaxv8vUEnBSamveOuvVvNnHPC_GgEzPMjkQXI178qsyQpQLxWfygf5vGPrGXNjDKJvNHDSeG-pgwp6YkwdXyLx5ZzR_C-oUvPzjgnOy7w7fizJiEuJTPqUAU6opVdlBe3OKBzMdCcZCIYBLpe5BbD2rP8tZ-Utj7JTm98BgrqtLDDELJyaJtq7DSeSQznk3D1UmmUb3k0W5pQ_9tV34GxQoxCKTt2HRndY3m00
If it can help,
Regards,
Th.