Skip to Content
Menu
This question has been flagged
3 Replies
11575 Views

Hello Everyone,

How to get the active_id and pass to return action from js code in odoo v10?

I've tried this.id, which gives null value.

My main goal is that i want to use the active id on the action which is being called through js code.

that action is opening wizard and in the default method of that wizard i want to use active id which is passed on context. but context gave None value. please help if you have any idea.


Best,

Prince.

Avatar
Discard
Best Answer

Hi Price Caspion

To give you a proper answer I will need more details about when it's needed the value of active_id and what kind of wizard are you launching, but assuming stuffs, here is some notes:

1- A normal Odoo wizard it's a form that contain fields, one field could have the value of the active_id as a default captured on the field default definition

@api.model 
def _get_active_id(self):
    return self._context.get('active_id')

deploy_config_id = fields.Many2one('res.partner', string='Customer', required=True, default=_get_active_id)

2- If you really need to get the value on JS here is a way that might work for you, depending of what you are doing 

var dataset = this.dataset;
var active_id = dataset.ids[dataset.index];

If your js code is executed on the form view of the wizard or something this.dataset will have the dataset where the dataset index is the position to the current record id in the dataset.ids array. If not is the case find a the proper dataset path to get the value using js debug using chrome developer tools or any similar tool for your browser

Hope this help you

Avatar
Discard
Author

Thanks Axel

Best Answer

Axel: do you know how to get active id in odoo 9? dataset is not working for me.

Thanks

Avatar
Discard
Related Posts Replies Views Activity
0
Dec 17
3210
1
Jun 24
316
1
Jan 20
6685
1
Aug 19
3573
1
Jul 19
2608