Skip to content

Placeholder Color Logic

This tutorial allows you to dynamically define a name for an Item Option using the name of the Colors assigned to them via object reference. Assuming a Family Item named "Shirt" with Item Options, each Option's optionName property will be derived from the associated Color. On Color updates, optionName will change dynamically based on the Color name, else fallback to the placeholderColor property.

This can be achieved with Formulas and properties defined on both the Plan Placeholder and Item entities.

Setting up Properties

The first step is to create a series of properties that will allow us to define our logic (the names of properties used in this tutorial are merely suggestions, feel free to adapt the names to your particular needs):

created_by_data_load:

This is an "All" level boolean property. If we are loading items using the loader, we might want to keep the already defined optionName from our csv file. This property can be used to keep this optionName provided we set it to true in our CSV load file and use the following code in our formula:

if (obj?.created_by_data_load === 'Yes') {
    return obj.optionName;
}
// The configuration file for our load should handle values like 'Yes' or any other value we want to use to define the boolean

color_name:

This is an Option level "object-reference" property. Usually a property like this will reference the color assigned to each option. This property will allow us to update the option names. We can do so adding the following code to our formula:

if (obj?.color_name){
    return obj.color_name.name;
}
// The optionName property will now hold the name of the color it references

placeholder_color

This is an Option level "string" property. The purpose of this property is to hold some value that could serve as a placeholder for our option name in case the previous two conditions don't apply. This would be our default value. We can add the following code to our formula to achieve this purpose:

else {
    return obj.placeholder_color;
}
// If the two previous conditions don't apply we will use the placeholder value

Setting up formula

Once we have created the corresponding properties, we will need to set up the complete formula in the optionName property like so:

if (obj?.created_by_data_load === 'Yes') {
    return obj.optionName;
} else if (obj?.color_name){
    return obj.color_name;
} else {
    return obj.placeholder_color;
}

To summarize the logic: If the option was created by data load, the optionName stated there will be used as our option name. Otherwise, if the option has a color_name, that color_name will be use as the option name. Finally if none of these conditions apply, the placeholder_color value will be used.