Expression for user group in View XML

Hi,

How do I get the current user group in this code:

  <panel name="detailPanel" title="Actions" sidebar="true">
    <button name="requestBtn" title="Request PR" showIf="statusSelect == 1 &amp;&amp; __user__.group.code == 'stoe'" icon="fa-bullhorn" onClick="save,action-purchase-request-set-status-requested,save"/>

user.group.code == 'stoe’

This expression don’t return the group of the current user

Can someone help me please ?

You may have to use a hidden field with __user__.group.code as value in order to load the object on client side

OK here is what I did:

I added new custom field as follow

Name: grpGroup
Type: String
Model: com.axelor.apps.purchase.db.PurchaseRequest
Model Field: attrs

On the Value Expression Tab I added:
__user__.group.code

I checked the Hidden check box in the “Options” panel

Now I changed my XML in the form-view as followings:

<panel name="detailPanel" title="Actions" sidebar="true">
    <button name="requestBtn" title="Request PR" showIf="statusSelect == 1 &amp;&amp; grpCode == 'STOE'" icon="fa-bullhorn" onClick="save,action-purchase-request-set-status-requested,save"/>
  </panel>

But its still not working.

What I am trying to do is that I want some buttons available for group/user and hidden for other, how can I do that ?

Hello,

There is also a keyword to get the group.code value in Javascript expression :

  • $group : contain the code of group for connected user
  • $user : contain the login of the connected user

Regards

1 « J'aime »

Thanks (gdu-axelor), it worked when I typed $group in the Value Expression tab in the Custom Field Window.

However, when I try to use the custom field to edit the View XML the button is not shown, I ran several tests and found that when I write this:

grpGroup == STOE

it checks them as string not their value, and since the string “grpGroup” is not “STOE” so its always false.

The code that I am trying to write:

<button name="requestBtn" title="Request PR" showIf="statusSelect == 1 &amp;&amp; grpGroup == STOE" icon="fa-bullhorn" onClick="save,action-purchase-request-set-status-requested,save"/>

This way a specific group can access part of the sequence not all the sequence.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.