This question has been flagged
2 Replies
38450 Views


Avatar
Discard

I would say that it is one of the first thing ton manage and learn well in Odoo.

Hello I wanted to ask if the external id is a field of each table in the database or a global one. 
Basically I have some products with and ID: 1,2,3,4,5,6..... but I also have some contacts with ID: 1,2,3,4,5,6,7... 
So initially I thougt external ID is a field that each table in the database of Odoo has, so I imported the products using the ID as the external ID, but when I am trying to import the contacts I am getting an error saying that external ID elready exist. 

So I guess the external ID is a "global" field is that right?
I was thinking if thats correct to convert my IDs from 0,1,2,3,4,.. to product_0,product_1,product_2,contact_0,contact_1,contact_2 
Will something like work?

The External ID is not the same as the Database ID. It is a globally or database wide unique string value. Yes, you can have "my_product.1" and "my_contact.1" and it is good practice to use the name of the model as part of the ID.

Best Answer

An External ID (also called XML ID) is a string identifier that uniquely identifies a particular record in Odoo.  

They become important when you plan to import data into Odoo.

When you import data, if you supply an External ID, Odoo checks if this record already exists.  If it does not, that line of your import file becomes an INSERT.  If it does exist, that line of your import file becomes an UPDATE.  If you don't supply an External ID (you leave it blank, or just don't supply the field at all), Odoo creates one automatically for you.

They are stored in the ir.model.data model and are not given to records that are created via the Odoo user interface - only for records that are imported (External ID is created or read on import) or exported (External ID is created on export if it doesn't exist already).

You can see the External ID for a record in Developer Mode using the View Metadata option in the Debug Menu.


When you export data, Odoo will ensure External ID's are present for every record in the export file, so you can update the file and import it back into Odoo (using the rules above).


 

Avatar
Discard

Clear Ray, and what is the maximum value of the external ID field, like what is the maximum range Odoo allows??

The field is a char field composed two smaller char fields separated by a period character. The first part is normally the name of the module creating the record, or some other prefix. Both char fields can have up to 10,485,760 alpha-numeric characters in total, except the period character. You will run into usability issues before your run into storage issues. After 66 characters in total, the ID won't display properly on the screen and you will have to scroll your browser to see it.

Hello, As we don't have a xml id for records that are added by user interface then if anyone wants to update records that added by user interface, Is there any way?

If you export the records, Odoo will automatically assign them an ID so that if they are re-imported, they will update instead of the import creating new records. Be sure to choose "I want to update data (import-compatible export)" during the export.

Best Answer

to add to the answer provided by Ray Carnes above. The External ID's work as PRIMARY KEYS (unique identifiers) that enables one to perform  something similar to CRUD (CREATE-READ-UPDATE and DELETE) activities. 
It does not matter the number of times you update, the external ID will ensure the right lines will ONLY be affected. 
when one does not provide/show the EXTERNAL ID during Mass loading/update, the system will treat each round of loading or update as different records or data hence will cause duplications. 

Note to ensure the External ID field is selected during an field or data export . 
Thanks. 

Avatar
Discard