Skip to Content
Menu
This question has been flagged
1 Reply
3061 Views

Hello everyone,

I am having a problem on testing a value on a many2many field on create() method.
I know that we should use:

         self.myfield_ids     : On write() method;
         vals['myfied_ids']  : On create() method;

I am trying to use "vals['myfield_ids']" on a many2many field and I am getting an "KeyError: 'myfield_ids'".
The code I have tried:

    if vals['myfield_ids']:
    returns: KeyError: 'myfield_ids'

How can I check if a many2many field is filled on form view for the create() method?
The field is not required on the form and I need to keep this way.

Thank you all in advance

Best regards

Paulo

Avatar
Discard
Best Answer

Instead of using  `if vals['myfield_ids']` then you should use `if vals.get('myfield_ids')`. The `get` method of dictionary will return None by default if the key isn't in the dict.

Avatar
Discard
Author

Dear Hoang,

Thank you very much for your help.

Best regards

Paulo

Related Posts Replies Views Activity
1
Feb 24
839
0
Jul 24
1503
0
Jul 22
60
1
Jul 22
1412
2
Dec 23
31970