Print field or global variable value in alert or console.log

How can we print the global/local variable value in UI?
I’m trying to gather add one validation but it’s not working so I thought to print the value first.

I’ve tried following in form view but didn’t worked.

<form name="my-form" title="MyForm"
      model="com.gpl.apps.db.MyDomain"
      width="large">
    <panel title="MyPanel">
        <field name="UserName" title="#{ __user__ }" />
    </panel>
</form>

Thanks…

Hello

I would like to point out some details here as you are trying with title attribute and __user__ variable :

  • __user__ will return the current logged in user which is type of User (not the string type).

  • title attribute will accept string type value.

  • title attribute won’t evaluate the value. It will display it as it is.

So to assign any value to title attribute runtime you can use action-attrs which you can specify on onLoad of form view. Plus fetch specific string value from User object so that it will display that specific value as title. something like : <attribute name="title" expr="eval: __user__.name" for="fieldName"/>.

So first need to clear which type of value specific attribute will accept and when we can assign it the value so that it will be evaluated.

Hope this details will be helpful !

Thank you.
Regards.