hi everyone how can i call a field values in file js odoo 15 please i need help
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Accounting
- Inventory
- PoS
- Project management
- MRP
This question has been flagged
In Odoo 15, you can call a field value in a JavaScript file by using the instance.web.form.FieldChar or instance.web.form.FieldSelection class, depending on the type of field you want to call.
For example, if you want to call the value of a Char field named "field_name", you can use the following code:
var field_value = instance.web.form.FieldChar.extend({
init: function () {
this._super.apply(this, arguments);
this.field_value = this.get_value();
},
});
And if you want to call the value of a Selection field named "field_name", you can use the following code
var field_value = instance.web.form.FieldSelection.extend({ init: function () { this._super.apply(this, arguments); this.field_value = this.get_value(); }, });
You can then use the field_value variable to access the value of the field in your JavaScript code. It's also important to note that you will have to import the 'web.form_common' module first in your file.
odoo.define('module_name', function (require) {
"use strict";
var form_common = require('web.form_common');
// your code here
}
Hey there,
Could you elaborate your answer ?
=> you say "if your field is called field_name", but you actually don't use "field_name" anywhere.
=> you import "web.form_common", but you don't use your variable "form_common" anywhere !
=> you use "instance.web.[...]", but "instance" of what exactly ? Used like, this, the browser won't understand "instance" which is undefined.
Thank you