Use the context on an action

When i create a new customer, i would like to alimentate isCustomer = True
So i create a new menu ans a new action

<action-view name="" title="Clients"
	<view type="cards" name="partner-contact-cards" />
	<view type="grid" name="partner-contact-grid" />
	<view type="form" name="ms-partner-contact-form" />
	<domain>self.isCustomer = true</domain>
	<context name="isCustomer" expr="eval:1"/>	

It doesn’t work.
Is it the good way ?
Thanks for help


I change

<context name="_isCustomer" expr="eval:1"/>

no more succeed

Normally the domain node is used to set a filter and the context node to set a var (not shure of that) not to set a value to a field.

I think you should create an attr-action to set your field value and call this action using the onLoad/onNew/onSave évent on your views/form according your needs . See here for action


Hello femtonext
thanks for your answer
Yes i think you’re right for the context but i tought that by using the same name that the name of a field you can set the value of this field

I try this

 <action-group name="action-group-product-onnew">
     	<action name="action-product-record-currency"/>
   <action-record name="action-product-record-currency" model="com.axelor.apps.base.db.Product">
 	    <field name="saleCurrency" expr="eval: company?.currency"/>

so as to set saleCurrency but it doesn’t work. I think i’m very near of the solution but …


I’m not behind my axelor but let me try on my side and i will go back to u.

Juste note that it should be an attribute action i think, i don’t know if it works with à record action



Following your requirement I made a test on the axelor-demo using Company

I created this attribute action:

<action-attrs name="action.attribute.home.set">
  <attribute name="value" expr="eval: true" for="home"/>

I call this action on the form using the onNew event:

<form name="company-form" title="Company" model="" onNew="action.attribute.home.set">

Now when I create a new company, the “home” field is set to true.

I don’t know if it’s the only one method or the best one but it works.


Thanks femtonext for your help.

This is my solution for my problem to auto-set currencies in product form.
I create an action group, i call it onnew

    <action-group name="ms-action-group-base-product-onnew">
	          <action name="ms-action-product-record-set-default"/>
    <action-record name="ms-action-product-record-set-default" model="com.axelor.apps.base.db.Product">
	          <field name="saleCurrency" expr="#{__user__.activeCompany.currency}"/>
	          <field name="purchaseCurrency" expr="#{__user__.activeCompany.currency}"/>

Great to hear that :slight_smile:

Another search which could interess people.
I need to set the Unit of a product by default : Unit (id =1)
I found the solution to attack a model and find a record like this

    <action-group name="ms-action-group-base-product-onnew">
	<action name="ms-action-product-record-set-default"/>
  <action-record name="ms-action-product-record-set-default" model="com.axelor.apps.base.db.Product">
	<field name="salesUnit" expr="eval: __repo__(Unit).find(1)"/>
1 « J'aime »

Good catch
__repo__(Object) is an shortcut used in Groovy expression to get repository instance. So all methods define in repositories can be used easily in xml action, most of the time to find and filter records : find, all().filter(...).fetchOne(), …

2 « J'aime »