How to fill dynamic fields with dynamic values within a loop?

Hey all,

I stumbled upon quite a cumbersome problem while creating a data processing workflow.

I have data returned from an API. I want to save each of these fields to the Odoo model custom.info.value.

[
  {
    "phone_number": "+11234567890",
    "name": "Cool Corp",
    "latitude": 90.11,
    "longitude": 20.20,
    "review_count": 100,
    "rating": 5
  }
]

For context, this model comes from a module called custom_info. It features three main models:

  • custom.info.property - Where you define properties and their type
  • custom.info.value - Where property values are stored
  • custom.info.template - Where you build templates by assembling properties

Example

Usually when you save data to Odoo using n8n - let’s say - creating a new partner, here’s what you do:

In this workflow, you already know the name of the field you wish to save your expression value to. You simply need to map your expression containing your value to the appropriate field and that’s it.

Now, in the case of the custom_info module, it’s not that simple.

Custom Info Module

Knowing that each row in the custom.info.value model must be linked to a property_id (a row inside the custom.info.property model), you can easily create “blank rows” in the latter. Meaning that you’d then have to update each of these rows with your desired value - in this case, the ones coming from the API data.

This means that your value is implictly linked to the property_id.

Let’s say you have a property_id 1 with the name of Longitude and wish to save the value longitude from your API into a new line. This would be easily feasible using a node per value, but in the case of a loop, you don’t want to do all of that manually.

The issue is that you’d have to match the property with both the field name of your value the value itself:

Any clues?

Make sure to ping me if there’s a need for clarifications.

Not sure I understand this correctly, but it sounds like you’re looking to loop through each of the values below and run your Custom Info Method node for them?

[
  {
    "phone_number": "+11234567890",
    "name": "Cool Corp",
    "latitude": 90.11,
    "longitude": 20.20,
    "review_count": 100,
    "rating": 5
  }
]

This could be done using a workflow like so:

Or would your property IDs have a different format? If so, can you share the property ID you’d like to use for each property name? Happy to update my above suggestion to replace these IDs as needed.

Almost this. Though, the property_ids aren’t in this format and aren’t at all linked to the payload in itself. They are integers:
So you have the value, the field (that allows you to make a match between the value and the field) and then the property_id that is an integer.

Each property has:

  • a value field, to store the actual value
  • a type, e.g. string, int, bool
  • an id, i.e. property_id

This is like an equation with three variables; we know the value, we know which field it corresponds to, and we have a property_id for each of the field values, but I don’t know how to make the correct match between all of this, nor how to illustrate correctly the issue