Skip to Content
Menu
Dette spørgsmål er blevet anmeldt
3 Besvarelser
832 Visninger

I make a new field in res.user called user_new_option and I want to add this value in the 
XML context  

<record model="ir.actions.act_window" id="model_user_new">
<field name="name">model.user.new</field>
<field name="res_model">model.user.new</field>
<field name="view_mode">tree,form</field>
<field name="context">{'user_new_option': uid}</field>
</record>

how can I do this. 

Avatar
Kassér
Bedste svar

Hi,

Please refer to the code:


<record model="ir.actions.act_window" id="model_user_new">

    <field name="name">model.user.new</field>

    <field name="res_model">model.user.new</field>

    <field name="view_mode">tree,form</field>

    <field name="context">{'user_new_option': user.user_new_option}</field>

</record>



Hope it helps.

Avatar
Kassér
Bedste svar

You can set the default value of field just need to add "default_" before the field like like default_user_new_option.

You can write code like below : 

<record model="ir.actions.act_window" id="model_user_new">
  ​<field name="name">model.user.new</field>
  ​<field name="res_model">model.user.new</field>
​<field name="view_mode">tree,form</field>
  ​<field name="context">{'default_user_new_option': uid}</field> </record> 

Avatar
Kassér
Forfatter

my friend, I do not want to set a default value, I just want to set the value from field "user_new_option" in the context "user_new_option"
like
user_new_option = self.env.user.user_new_option
how can I do something like this

Bedste svar

How to set a default value for a field when creating a new record using the context?

Here's how it's done:


<record model="ir.actions.act_window" id="model_user_new"> <field name="name">model.user.new</field> <field name="res_model">model.user.new</field> <field name="view_mode">tree,form</field> <field name="context">{'default_user_new_option': 123}</field> </record>

Avatar
Kassér
Forfatter

I want to get the value from the field in res.user because I want to make it changeable when I change it in the user form It changed in the context

Forfatter

I mean to get it from the user like self.env.user.user_new_option

Related Posts Besvarelser Visninger Aktivitet
3
jul. 25
7241
1
maj 25
1247
2
jan. 25
2025
1
jan. 25
1487
1
aug. 24
1964