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
From this list, you can pick individual key/value pairs like idand 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:
Setting
Value
Rendering Type
Advanced List
List Display Selector
name
List Value Selector
id
List Items
Important! Make sure the idparameter is an integervalue (not wrapped in quotes "")
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.
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:
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:
Setting
Value
Rule Type
Import
Rule Name
Text Manipulation
Value
Enabled for
Odoo only
ProTip: Open the browser dev tools (F12) and add a line
console.log('attributeValues', attributeValues);
immediately before the return line to see the values at runtime + troubleshoot them. When you're done, simply remove it again.
If the value for attribute_id is not an array, change the text
to this
If you get an error reading
Fail: Failed to evaluate rule with error: TypeError: s.map is not a function
Add a new import rule before the selection import rule to convert the text to JSON (enabled only for Odoo):
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