A Loaded Rule is useful to initialize the configurator with default values. Unless the user refreshes their web browser or leaves the configurator and returns to it, this rule will not be run again.
Just after a new configurator is created or an existing configured product is loaded, these steps are performed before the configurator appears on-screen:
- Value Rules run.
- Loaded Rules run.
- Value Rules run again. (This pair of value rules before and after the loaded rule ensure information flows up and down any nested configurator relationships.)
- The UI then appears on-screen.
Arguments
Arguments are variables passed in to the rule. You can find them by using the Get/Set variable snap blocks. In this rule type, the Get block exposes these arguments:
Name | Type | Description |
---|---|---|
clientLanguage | text | the two-character code representing the current user's preferred language. |
configurator | Configurator | the current running configurator. |
environment | string | "dev" if you are in the development environment, "test" if you are in the test environment, and "prod" if you are in the production environment. |
isEdit | boolean |
true if the configurator that is being loaded is an edit of a pre-existing configured product inside a quote; false if it's a new, never-before-saved configurator accessed from the product page. |
isMobile | boolean | true, if the viewport seems to have the size of a mobile device. Use this flag to show something differently on screen if required by a smaller device. |
parameters | map | a map of parameters passed into the configurator when it was launched. |
quoteProduct | quoteProduct | If this configurator has been saved, then it exists as a configuredProduct, a type of quoteProduct, within a Quote. This attribute gives you visibility to some information from this context, such as files attached to the quoteProduct or volumediscounts applied because of the quantity ordered. |
user | User | the current user. |
Examples
1. Disable certain fields if the configurator was previously saved
A common use for the loaded rule is to determine if this is editing an existing configured product and, if so, disable a field. This might be necessary if you wish to only allow people to set a field once and, due to some business requirement, cannot be set to another value after it has already been added to a quote.
2. Make certain fields visible, depending on the user's role
In this Loaded rule, if the person launching the configurator is a Company Administrator, any field that has the string "(hidden)" as part of it's label is made visible. This can be a technique for showing hidden fields in the UI to administrators, to help with your design or troubleshooting work. First, hide or show fields for most users by setting the visibility of the field directly in the definition of the field. Then, use a function like this one to make certain fields always visible to administrators.
3. Make parameters passed in from other systems more broadly available to more code.
Your configurator may be launched within the context of another system, such as within an ERP system like Epicor Kinetic or as part of a CRM screen like Salesforce. Important information from these other systems are often passed into a configurator through parameters. The "get" Snap block contains all this information when the configurator is first launched, but if the configurator is saved and re-opened, the get block may not contain that same information.
Solve this problem by storing these parameters for future use, or for downstream applications. Use a loaded rule to serialize the parameters as JSON to a hidden text field in your configurator. Once the parameters are in a field, it's easy for them to be de-serialized and used by any downstream process.
Data of any type and reasonable size is easy to serialize into JSON, and store in a text field in your configurator. Here's an example of data serialization.
Snap rules run in a specific order, and in response to specific events. Learn more about rule execution order.