Display All Attribute Names
To view the values of a Product Template's attributes in SharpSync, use the Property Mapping list product.attribute
(see also List Names)
The list product.attribute
is special in that you can expand upon the query by adding attribute name at the end in square brackets. See Display Single Attribute Values
Start by adding a Property Mapping for
product.template.attributes
Primary Accessor
(Unmapped)
Secondary Accessor
product.template.attribute_line_ids
List Name
product.attribute
List Value Selector
{id}:{name}
Prefer Odoo Value
checked
Update Odoo on submit
unchecked. (We'll enable the update for individual names)
Open the Property Mapping > Settings and enter a
List Name
of
product.attribute
Click the Save
button. The list preview will update and show values like this
{
"create_variant": "always",
"display_type": "color",
"display_name": "Color",
"id": 2,
"name": "Color",
"number_related_products": 4,
"sequence": 20,
"value_ids": [
3,
4,
11,
12
]
}
|
{
"create_variant": "always",
"display_type": "radio",
"display_name": "Legs",
"id": 1,
"name": "Legs",
"number_related_products": 6,
"sequence": 10,
"value_ids": [
1,
2,
8
]
}
From this list, you can pick individual key/value pairs like id
and name
as a List Value Selector
Change the List Value Selector
to
{id}:{name}
Click the Save button, then the refresh button next to the list preview.
This will shorten the list to
1:Legs|2:Color|3:Duration|5:Finish
We have the information we need, lets make this dynamic in the SharpSync Bill of Material view
Setup a Render Type
We have the values returned from the above list is as follows:
1:Legs|2:Color|3:Duration|5:Finish
This means each attribute has an internal id `id`, and a display name or 'name' value associated with the id value. Our next step is convert this list to a list of JSON objects in the form
[
{ "id" : "id1Value" , "name" : "displayName1" },
{ "id" : "id2Value" , "name" : "displayName2" }
]
You can create this by hand or use the following handy prompt in Copilot or ChatGPT with your text string pasted after:
Convert the following string into a JSON array with "id" and "name" key value pair objects. The keys must be integers
Click the copy button next to the generated list of values
In SharpSync make the following changes to the Property Mapping:
Rendering Type
Advanced List
List Display Selector
name
List Value Selector
id
List Items
[
{ "id" : 1, "name" : "Legs" },
{ "id" : 2, "name" : "Color" },
{ "id" : 3, "name" : "Duration" },
{ "id" : 5, "name" : "Finish" }
]
Click the save button
Pro Tip: You could add a { "id" : 0, "name" : "" } item to show blank values when nothing is found and trigger a display rule to warn you.
[
{ "id" : 0, "name" : "" },
{ "id" : 1, "name" : "Legs" },
{ "id" : 2, "name" : "Color" },
{ "id" : 3, "name" : "Duration" },
{ "id" : 5, "name" : "Finish" }
]
You now have the values in the list, but nothing will yet display in the Bill Of Materials view.
The next step will be to parse the values from Odoo so that it automatically selects the correct value onscreen when the BOM is loaded from Odoo.
Add a new Rule Mapping
The values that arrive from Odoo are complex nested values (the type is nestedObject
in SharpSync) and looks something like this:
[
{
"id": 27,
"value_count": 2,
"sequence": 10,
"attribute_id": {
"id": 1,
"display_name": "Legs"
},
"value_ids": [
{
"id": 1,
"display_name": "Steel",
"color": 9
},
{
"id": 2,
"display_name": "Aluminium",
"color": 3
}
]
},
{
"id": 28,
"value_count": 2,
"sequence": 11,
"attribute_id": {
"id": 2,
"display_name": "Color"
},
"value_ids": [
{
"id": 3,
"display_name": "White",
"color": 3
},
{
"id": 4,
"display_name": "Black",
"color": 3
}
]
}
]
This must be converted this to a more readable format for the BOM comparison screen, so we'll make use of an import rule
.
Navigate to the Property Mapping. Add a new Import Rule:
Rule Type
Import
Rule Name
Text Manipulation
Value
const valueWhenNoJson = [0];
if (!s)
{
return valueWhenNoJson;
}
/* Extract attribute values into a new array */
/* Removes falsy values like undefined */
const attributeValues = s.map(item => item.attribute_id && item.attribute_id[0]).filter(Boolean);
return (attributeValues?.length ?? 0) > 0 ? attributeValues : valueWhenNoJson;
Enabled for
Odoo only
This will return a string of 'ids' as a result, select the values from the list of values to the screen, and return the selected values

Last updated