How do I retrieve a participant full name from a procedure/function?

+1 vote
asked Sep 14, 2022 in Question / help by vincenzo.dimassa (120 points)

In the following I get the note rendered as "message from U1 to U2"

PlantUML Diagram

Is it possible to retrieve the entity full names and thus obtain the note "message from User1 to User2".

I'd like to obtain that by just modifying $myProc

@startuml
entity User1 as U1
entity User2 as U2
!procedure $myProc($s1, $s2)
  $s1->$s2
  note left: message from $s1 to $s2
!endprocedure
$myProc("U1", "U2")
@enduml

1 Answer

0 votes
answered Sep 14, 2022 by The-Lu (70,400 points)

Hello V.,

If you use only `entity`, you can use JSON variables, as:

@startuml
!$json = { 
"users" : [
  {"alias": "U1", "name": "User1"},
  {"alias": "U2", "name": "User2"},
  {"alias": "U3", "name": "User3"}
]
}
!foreach $u in $json.users
entity $u.name as $u.alias
!endfor

!procedure $myProc($s1, $s2)
  !$i=$s1 -1
  !$j=$s2 -1
  $json.users[$i].alias -> $json.users[$j].alias
  note left: message from $json.users[$i].name to $json.users[$j].name
!endprocedure

$myProc(1, 2)
$myProc(3, 2)
@enduml

See also help on:

If that can help,
Regards,
Th.

commented Sep 14, 2022 by vincenzo.dimassa (120 points)
Hello Th,

It is a nice proposal. I was trying something like this myself.

But I'm looking for a solution that does not require to change how my entities are defined.

Kind Regards,

V.
commented Sep 15, 2022 by The-Lu (70,400 points)

Hello V.,

You are right.
Currently it is not possible to know label or name from alias...

And that can be difficult for more complex naming, as:

@startuml
entity User1 as U1
participant U2 [
=A complex User 2
----
* with multi-line
* creole element
* ...
]
actor User3 as U3
!procedure $myProc($s1, $s2)
  $s1->$s2
  note left: message from $s1 to $s2
!endprocedure
$myProc("U1", "U2")
@enduml

Regards,
Th.

commented Sep 15, 2022 by V.
Hi again Th,

I see.  There are corner cases that prevent a straightforward implementation.

Maybe I'll look into the code/spec to understand if something like python's repr could be implemented... some day!

Thanks in the meantime
V.
...