Use the context on an action

Hello
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="ms.general.partners" title="Clients"
	model="com.axelor.apps.base.db.Partner">
	<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"/>	
</action-view>

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

MDEL

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 https://docs.axelor.com/adk/5.0/dev-guide/actions/action-attrs.html for action

Regards

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

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

Hi,

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

Regards

Hi,

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"/>
</action-attrs>

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

<form name="company-form" title="Company" model="com.axelor.contact.db.Company" 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.

Regards

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-group>
  
    <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}"/>
    </action-record>

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-group>
  
  <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)"/>
  </action-record>
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 »