# On\_change on a selection field inside a one2many field

**URL:** https://discuss.tryton.org/t/on-change-on-a-selection-field-inside-a-one2many-field/1552
**Category:** Developer
**Created:** [July 11, 2019, 11:59am UTC](https://discuss.tryton.org/t/on-change-on-a-selection-field-inside-a-one2many-field/1552 "2019-07-11T11:59:15Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Monika](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/m/f05b48/32.png) [@Monika](https://discuss.tryton.org/u/Monika)
#### Post date: [July 11, 2019, 11:59am UTC](https://discuss.tryton.org/t/on-change-on-a-selection-field-inside-a-one2many-field/1552/1 "2019-07-11T11:59:15Z")

</div>

I am trying to use a on\_change method. The field that I am trying to use it on is a selection field. The selection field is on a one2many field that tries to use the value from the parent view. Example -

```
@fields.depends('patient', 'attendants_relation')
    def on_change_attendants_relation(self):
        if self.attendants_relation == 'Self':
            self.attendant_name = self.patient.patient_name 

```

here the ‘patient’ is the many2one field that is created to create a one2many field.

On changing the attendants\_relation here, self.patient comes as None (until the record in one2many is not saved). Is there any way to access the data from the parent view ?

---

<div class="post-metadata">

### Author: ![oscarQ](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/oscarq/32/413_2.png) [@oscarQ](https://discuss.tryton.org/u/oscarQ)
#### Post date: [July 11, 2019, 12:41pm UTC](https://discuss.tryton.org/t/on-change-on-a-selection-field-inside-a-one2many-field/1552/2 "2019-07-11T12:41:17Z")

</div>

I’m not sure if there is a way to fill the selection field doing it this way, so maybe I’m wrong, but I would set the on\_change on the one2many field, and iterate all the rows, setting the value for the attendants\_relation field when it is needed.

---

<div class="post-metadata">

### Author: ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)
#### Post date: [July 11, 2019, 12:51pm UTC](https://discuss.tryton.org/t/on-change-on-a-selection-field-inside-a-one2many-field/1552/3 "2019-07-11T12:51:35Z")

</div>

> [@Monika](#):
>
> Is there any way to access the data from the parent view ?

Yes but you must tell the [client to do so by filling depends](http://docs.tryton.org/projects/server/en/latest/ref/models/fields.html?highlight=_parent_#one2many) like this:

```
@fields.depends('patient', '_parent_patient.patient_name', 'attendants_relation')

```

It is always better to keep the ‘patient’ field like that it will still work if the record is edited outside the One2Many.

---

<div class="post-metadata">

### Author: ![Monika](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/m/f05b48/32.png) [@Monika](https://discuss.tryton.org/u/Monika)
#### Post date: [July 16, 2019, 8:19am UTC](https://discuss.tryton.org/t/on-change-on-a-selection-field-inside-a-one2many-field/1552/4 "2019-07-16T08:19:03Z")

</div>

Thank you for helping!

---

<div class="post-metadata">

### Author: ![system](https://discuss-cdn.tryton.org/uploads/default/original/1X/c6f8ec0a40525cdcd50058c734283450a4b3d38b.png) [@system](https://discuss.tryton.org/u/system)
#### Post date: [August 15, 2019, 8:19am UTC](https://discuss.tryton.org/t/on-change-on-a-selection-field-inside-a-one2many-field/1552/5 "2019-08-15T08:19:05Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
