SharpSync
  • Welcome
  • Fundamentals
    • Getting Started
      • Registration
      • Landing Page
      • Support
      • Subscription
    • Data Sources
    • Property Mappings
    • Rule Templates
    • BOM Comparison
    • Data Safety
    • Troubleshooting
      • Duplicate component paths
      • OAuth 2.0
  • Data Sources
    • Autodesk Inventor
    • CSV
      • Getting Started
      • Importing a Bill of Materials (BOM)
    • MS Dynamics 365 Business Central
      • Getting Started
      • Item Fields Json & Internal Names
      • Resource Fields Json & Internal Names
      • List Names For nestedObject Mappings
    • NetSuite
      • OAuth Setup
        • Permissions
      • Suite API Setup
      • Create an uploads folder
      • Setting up a thumbnail folder
      • Authentication + Configuration
      • Common setup
        • Configure quantity mapping
        • Configure accounts mappings
        • Configure itemType mapping
        • Configure isPhantom mapping
        • Configure subsidiary mapping
        • Configure price mapping
        • Configure Where Used Link mapping
        • Configure thumbnail mapping
        • Common Mapping Rules
        • Common List names
      • Advanced Bill of Materials
      • Configure Server Side Script
        • Example Server Side Script
      • Configure SharpSync to use Server Side Script
      • Configure Routings
      • Integration tips
      • Troubleshooting
    • Odoo
      • Getting Started
        • Authentication + Configuration
        • Debugging tips
      • Common Setup
        • Map BOM Codes
        • Map BOM Types
        • Map Attribute Values
          • Reading Attributes - Overview
          • Display All Attribute Names
          • Display Single Attribute Values
          • Writing attributes
      • Product Management
      • Hosting Options
      • List Names
      • Permissions
    • Onshape
      • Getting Started
      • Setting up Derivatives
    • Propel PLM
      • Getting Started
    • SolidWorks
    • SolidWorks PDM
      • Downloading and installing the add-in
      • Configure the add-in
      • Setting up the Solidworks PDM Web 2
      • Troubleshooting
      • Submitting a BOM for update
  • Property Mappings
    • Property Mapping Settings
      • Rendering Types
    • Rule Templates
      • Import / Export
        • Append text
        • Calculate number
        • Export manipulation
        • Format as decimal number
        • Prepend text
        • Remove property
        • Replace all instances
        • Replace first instance
        • Round to nearest X
        • Select from JSON
        • Set cell value
        • Set empty cells
        • Text manipulation
      • Display
        • Number between
        • Text contains
        • Text ends with
        • Text evaluation
        • Text is a number
        • Text is exactly
        • Text is in list
        • Text is not a number
        • Text is not empty
        • Text is not in list
        • Text length between
        • Text length is exactly
        • Text maximum length
        • Text minimum length
        • Text not contains
        • Text not ends with
        • Text not starts with
        • Text starts with
  • Advanced
    • Derivatives
    • Advanced Scripting
  • User management
    • User Management
    • Application Permissions
Powered by GitBook
On this page
  • Setup a Render Type
  • Add a new Rule Mapping
  1. Data Sources
  2. Odoo
  3. Common Setup
  4. Map Attribute Values

Display All Attribute Names

PreviousReading Attributes - OverviewNextDisplay Single Attribute Values

Last updated 17 days ago

To view the values of a Product Template's attributes in SharpSync, use the Property Mapping list product.attribute (see also )

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 for

product.template.attributes

Setting
Value

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 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" }

]

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 integer value (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.

[ 
  { "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:

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

s.map(item => item.attribute_id && item.attribute_id[0]).filter(Boolean);

to this

s.map(item => item.attribute_id && item.attribute_id.id).filter(Boolean);

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):

return JSON.parse(s ?? "[]");

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

You can create this by hand or use the following handy prompt in or with your text string pasted after:

[ 
  { "id" : 1, "name" : "Legs" },
  { "id" : 2, "name" : "Color" },
  { "id" : 3, "name" : "Duration" },
  { "id" : 5, "name" : "Finish" }  
]
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;
List Names
Property Mapping
Copilot
ChatGPT
Showing all mapped attribute names