Rules are possibly one of the most useful and powerful tools you will be using on your journey with Asgard Labels. Rules allow you to filter or create conditions for particular label models when printing. In other words, you can create rules that will have labels displayed on the screen, depending on the fulfillment of certain conditions, while other models remain hidden. Rules can also be used to restrict the printing of certain labels. A use case for this would be prevention of printing labels meant for the shipment to Company B when preparing a shipment to Company A. By restricting the printing of the label for Company B, you can be sure that there wouldn't be any mix up or errors.
Configuring a rule
To configure a rule, we begin by giving the rule an identifier and a description. Ideally the latter fields should be given names that are easily readable and properly describe the rule. For instance, given a rule that will filter retailers could be named “ISRETAILER” and have a description of “Is Retail Company”. Next, you need to select a screen to which this rule will apply to. By mapping the rule to a screen, you can use the fields from the screen to make your rule.
Before demonstrating how to write a rule expression, we need to go over the two types of rules.
Non-Composite vs. Composite Rules
A non-composite rule is a singular rule. It is typically based on and will fulfill one condition. For instance, the following rule “ISCOSTCO” is a non-composite rule because it requires only one condition to fulfill; is the current shipment to a customer named Costco?
Thus, this rule will look at the customer ID of the shipment and evaluates if the customer is Costco.
A composite rule is an aggregate of non-composite rules. In other words, if a rule is made of two or more non-composite rules, then it is a composite rule. Composite rules fulfill multiple conditions. For instance, given two non-composite rules “ISCOSTCO” and “ISWALMART”. Both rules evaluate the customer ID of the shipment. The former check for Costco shipments while as the latter check for shipments to Walmart. If we wanted to group these two companies under a same category, we could categorize them as retailers. So, if we were to create a rule that would evaluate retail companies, we would need to create a composite rule to envelope the two companies. The following image details the configuration of said composite rule.
To make the composite rule, simply add the two non-composite rules to the “Rule Details” Tab. Thus, for this rule to be fulfilled, the companies evaluated need to either be Costco or Walmart for a shipment to be recognized as a retail shipment.
Writing expressions
Writing an expression for your rule requires a little bit of technical knowledge; however, we will breakdown the simplest rule so you can get an idea on how expressions are created. The expression we will be analysing is the “ISCOSTCO” rule, which has the following structure:
{{Document != null && Document.CustomerID != null && (Document.CustomerID?.AcctCD | string.strip == 'COSTCO')}}
Looking at the expression, the expression may seem a little daunting, however, we can break it down into 3 easily digestible parts.
Reminder: the “ISCOSTCO” rule is mapped to the shipments screen (SO302000).
Document != null | In this section of the expression, you are verifying that the document, which is a view on the shipment screen, is not empty (null). The document view is in the summary portion of the screen. |
Document.CustomerID != null | In this part, you are verifying that the customer ID, from the Document view, is not empty (null). In other word, there should be a customer to which the shipment is addressed to. |
(Document.CustomerID?.AcctCD | string.strip == 'COSTCO') | For this section, there are a couple of expressions to unpack. First, you are looking at the account name of the customer. The question mark (?) is meant to handle empty (null) expression. So in the eventuality that no name is found, the “?” will handle that issue. Next, there is the string.strip function, which will remove any leading or trailing space in the name. It is essentially a way to make sure the name is well formatted to fit the specified name. Lastly, with the == 'COSTCO' , you are comparing the customer’s name that is pulled from the system and the specified company name “COSTCO”. If the account name does not match “COSTCO”, then the rule is not fulfilled. |
The following explains the significance of the operators.
&& | Is a logical operator that means AND |
!= | Is an inequality operator that means NOT EQUAL TO |
== | Is an equality operator that means EQUAL TO |
?. | is the null conditional operator which will immediately return null if the expression on its left-hand side evaluates to null. |
| | is a separator to allow for another function to be evaluated by the expression. |
Detail Section
When it comes to the detail section of the Rules screen, no configuration is needed if the rule is non-composite. The rows will populate themselves as the rule is assigned to models or used to build composite rules.
Closing
So now that you have the basic tools to create your label rule, you can start playing around with creating different rules and getting familiar with expression writing.