Get the name of the widget from a groovy script

Hi,

I m using Bonita BPM 6.3 and I m trying to figure out if it is possible from a groovy script to get the name of the widget the script is part of.

For example, I have a “Message” widget called “Message1”. In the groovy script setting its initial value, is there a variable storing its name (Message1) which I could access ?

Thank you

Hello,
there is a naming convention to have “field_WidgetName” in order to get a value of a certain widget. In your case, field_Message1 in a groovy script would allow you to get a current widget value. But on the other hand, you wouldn’t use that to set a widget value. It is enough to define a return value in the groovy script setting widget initial value (no need to access to any variable). You shouldn’t do any association within groovy script, but you should rather use their return values to update variables.
Hope this helps,
Haris

Thank you for your answer. I’m not interested by widget value, I 'm trying to get its name.

My apologies for misunderstanding your question.
There is no variable that contains a widget name.
Could you explain us your use case a bit more, why do you need the widget name during initialization? Maybe we can find another way to do it…

I have several forms with several widgets. The initial value of each widget is stored in a hashmap with the name of the widget as a Key. Rather than having to modify every initial value script to set a variable with the widget name. I wanted to automate things by creating template widgets I could copy/paste in my forms. If i were able to access the name of the widget, with the right scripts, I would just have to change the name of the widget from the “template widget” I pasted and I wouldn’t have to modify any of the groovy scripts.

Thanks for sharing the details, I understand your needs.
Maybe a group widget functionality (that exists only in Subscription version) could help you to achieve that. Group is defined as a map that uses widget names as keys.

Thanks a lot. I ll look into it