Siirry sisältöön
Menu
Sinun on rekisteröidyttävä, jotta voit olla vuorovaikutuksessa yhteisön kanssa.
Tämä kysymys on merkitty
1 Vastaa
1129 Näkymät

Hi good day!, 


I just want to as on how to assign/send/copy long text field value to another text field in odoo 10 by a xmlrpc webservice.

Thank you very much in advance! 



Avatar
Hylkää
Paras vastaus

- Firstly, you have to set up the connection to your odoo instance : 

```

import xmlrpc.client 

url = 'http://your-odoo-server'

db = 'your-database-name'

username = 'your-odoo-username'

password = 'your-odoo-password'

common = xmlrpc.client.ServerProxy('{}/xmlrpc/2/common'.format(url)) 

uid = common.authenticate(db, username, password, {}) 

models = xmlrpc.client.ServerProxy('{}/xmlrpc/2/object'.format(url))

```

- Then, you can fetch the record IDs you want to copy, you can use 'search and read' to get it

```

model_name = 'your.odoo.model'  # Replace with your actual Odoo model name

record_ids = [1, 2, 3]  # Replace with the IDs of the records you want to update

```


- finally, you deal with these record IDs and proceed to the update,

```

for record_id in record_ids:

    record = models.execute_kw(db, uid, password, model_name, 'read', [record_id], {'fields': ['field_to_copy', 'target_field']})


    # Check if the source field has a value

    if record[0]['field_to_copy']:

        source_value = record[0]['field_to_copy']


        # Update the target field with the source value

        models.execute_kw(db, uid, password, model_name, 'write', [[record_id], {'target_field': source_value}])

```

*** Please note that if you are working with long text fields, the API response might not include the complete text in a single call. You may need to adjust your code to handle this situation based on your specific requirements.


*** I hope it can be helpful. Thx

Avatar
Hylkää
Aiheeseen liittyviä artikkeleita Vastaukset Näkymät Toimenpide
2
kesäk. 24
1322
1
huhtik. 23
1279
1
maalisk. 23
2080
0
jouluk. 22
1740
1
lokak. 21
3663