Community mailing list archives

community@mail.odoo.com

Getting field in javascript

by
heba.fahmy
- 01/28/2015 03:21:26

Dear all,,

 

I work on odoo 8 and I want to get the value of  model field in javascript code to do certain action when this field  has certain value.

 

I tried the following idea but it doesn’t work:

var model = new instance.web.Model("survey.user_input");

model.call("get_state", {context: new instance.web.CompoundContext()}).then(function(result) { alert(result)});

 

 

and in the survey.user_input I created the following function

 

def get_state(self, cr, uid, automatic=False, context=None):

 

        user_input_ids = self.search(cr, uid, [],context=context)

        id = len(user_input_ids)-1

        survey_obj = self.browse(cr, uid, id, context=context)

        return {'state': survey_obj.state}

 

 

How can this be performed?

 

Thanks in advance.