# Update field string dynamically

**URL:** https://discuss.tryton.org/t/update-field-string-dynamically/4622
**Category:** Developer
**Created:** [September 15, 2021, 6:02am UTC](https://discuss.tryton.org/t/update-field-string-dynamically/4622 "2021-09-15T06:02:48Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![taiheui0114](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/t/35a633/32.png) [@taiheui0114](https://discuss.tryton.org/u/taiheui0114)
#### Post date: [September 15, 2021, 6:02am UTC](https://discuss.tryton.org/t/update-field-string-dynamically/4622/1 "2021-09-15T06:02:48Z")

</div>

Hi all,

Is there any way to update tree/form string attribute dynamically based on certain field value? I’ve tried to add the logic in view\_attributes() but it did not work.

```auto
    @classmethod
    def view_attributes(cls):
        return super(x, cls).view_attributes() + [
            ('//label[@name="quantity"]', 'string',If(Eval('transfer_type') =='request', 'Request Quantity', 'Transfer Quantity'))]

```

The quantity string will be updated based on transfer\_type value. If user select “request” type, the quantity will be displayed as “Request Quantity” instead.

Thank you.

---

<div class="post-metadata">

### Author: ![JCavallo](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/j/48db29/32.png) [@JCavallo](https://discuss.tryton.org/u/JCavallo)
#### Post date: [September 15, 2021, 6:44am UTC](https://discuss.tryton.org/t/update-field-string-dynamically/4622/2 "2021-09-15T06:44:20Z")

</div>

Hello,

For tree views this is impossible AFAIK, since the column name is independent of the list of records.

For form views, a workaround would be to define a separate Function (Char) field, and use it as a label for the field.  
So the string value would be computed in the function field getter, and displayed in place of the label of the main field.

Basically, replace:

```xml
<label name="quantity"/>

```

with

```xml
<label name="quantity_label" string=""/>

```

_Edit: used string= rather than widget= in xml_

---

<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: [September 15, 2021, 6:44am UTC](https://discuss.tryton.org/t/update-field-string-dynamically/4622/3 "2021-09-15T06:44:21Z")

</div>

No the string of labels are static. This is mainly because they are used on list as column header.

On form you can put some labels in side the same group and make them visible one at a time using a PYSON expression on each one.  
But the general idea of Tryton is that a field represents a unique concept.

---

<div class="post-metadata">

### Author: ![taiheui0114](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/t/35a633/32.png) [@taiheui0114](https://discuss.tryton.org/u/taiheui0114)
#### Post date: [September 15, 2021, 7:38am UTC](https://discuss.tryton.org/t/update-field-string-dynamically/4622/4 "2021-09-15T07:38:46Z")

</div>

Thank you for your prompt reply. I was thinking to use view\_ids on field to separate the form and tree views. Is there any way to dynamically set the view\_ids based on record value?  
For instance, set the view\_ids to X when Eval(‘transfer\_type’) ==‘request’ whereas set the view\_ids to Y when Eval(‘transfer\_type’) ==‘return’.

Thank you

---

<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: [September 15, 2021, 7:43am UTC](https://discuss.tryton.org/t/update-field-string-dynamically/4622/5 "2021-09-15T07:43:56Z")

</div>

> [@taiheui0114](#):
>
> Is there any way to dynamically set the view\_ids based on record value?

No, you must consider that in Tryton all the views are static (and you can just manage to hide/show (with states) parts of it).

---

<div class="post-metadata">

### Author: ![taiheui0114](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/t/35a633/32.png) [@taiheui0114](https://discuss.tryton.org/u/taiheui0114)
#### Post date: [September 15, 2021, 9:57am UTC](https://discuss.tryton.org/t/update-field-string-dynamically/4622/6 "2021-09-15T09:57:57Z")

</div>

Thank you for your clarification.
