Replace the Label Template (XML)
You can use a business rule to determine which label template to use when processing a print request. The business rule can create a request for a particular label template based on data in the print request. For example, you can convert a request for a generic shipping label to a customer-specific shipping label based on the customer ID.
Important! Content in a business rule is case sensitive. This includes business rule component names, attributes, and values.
Tip: If you always want to use the same label template when a particular simple process is run, you can specify the path to that label template in the Document field for the process. You do not need to use a business rule unless you also want to implement business logic.
The following business rule changes a shipping label template based on the customer ID specified for the job. The SHIPPING_XREF table in the database includes columns named CUSTOMER_ID and SHIPPING_LABEL. This business rule can be run by a simple process.
Note: This business rule requires the existence of a JDBC data service that establishes a connection to a database. In the data service, Is Parameter is selected for the SQL Query. For more information,
<?xml version="1.0" encoding="UTF-8"?>
<businessRules configuratorSupport="false">
<businessRule>
<dataService name="LOOKUP_DATASERVICE" namespace="Body" sticky="true" failOnNoRows="false" mergeRowToJobData="false">
<!-- Triggered by ENQUEUE event. -->
<triggers>
<trigger eventTrigger="ENQUEUE" priority="0"/>
</triggers>
<!-- Query the database using the customer ID to find the appropriate label template. -->
<parameters>
<parameter parameterKey="query" resolveValue="true">
<parameterValue>SELECT SHIPPING_LABEL FROM LW_QA.SHIPPING_XREF WHERE CUSTOMER_ID=${/Body/company}</parameterValue>
</parameter>
</parameters>
<!-- Check whether the request is for a shipping label. -->
<executionCondition>
<equalsIgnoreCase failOnFalseCondition="false">
<trueLogMessage>*** DETECTED SHIPPING LABEL ***</trueLogMessage>
<left type="KEY" valueType="STRING">
<value>${!DOCUMENT_URL!}</value>
</left>
<right type="LITERAL" valueType="STRING">
<value>SHIPPING</value>
</right>
</equalsIgnoreCase>
</executionCondition>
<children>
<mapOperations name="UPDATEMAP" namespace="Body">
<!-- The mapOperations business rule component is triggered by the SET_FORMAT event, which occurs once for each row returned by the database query -->
<triggers>
<trigger eventTrigger="SET_FORMAT" priority="0"/>
</triggers>
<!-- Assign the final label template. -->
<operations>
<operation action="OVERRIDE" dataType="STRING" literalValue="false" operation="PUT">
<!-- Name (key) for the label template -->
<targetKey>/!DOCUMENT_URL!</targetKey>
<!-- Value for SHIPPING LABEL returned from the current row of the database. This value is the fully-qualified path to the label template in Spectrum (such as /Loftware/Portsmouth/Labels/PortShip). -->
<value>@{SHIPPING_LABEL}</value>
</operation>
</operations>
</mapOperations>
</children>
<!-- Path to a data service in Spectrum -->
<dataServiceUrl>/Loftware Inc/BRE/dsvc1</dataServiceUrl>
<!-- Create a custom event to occur once for each row returned by the database query. Mapping tables should only return one row of data for the query. If more are returned, only the last row returned is used. -->
<perRowEvents>
<rowEvent eventName="SET_FORMAT" includeSiblings="false"/>
</perRowEvents>
</dataService>
</businessRule>
</businessRules>