Recently a partner presented us with an interesting use case.
Suppose you have a boolean field on
your product records to specify that certain products are in stock (actually this will be an
option list field with options "True" and "False"). Is there a way to add a fixed out-of-stock
image to your design template which is only used for products that are out of stock?
In today's post we will show how to accomplish this kind of conditional pagination using
PageBuilder 3.4.1.
The first step is to add the out-of-stock image in ADAM by creating a new record with the image
as file in it. Next, we can link this record to the product records that are out of stock
using a new record link field which we call "OutOfStockImage".
Of course we do not want to request product managers to manually keep this new field in sync
with the existing option list field, so whenever the "InStock" field changes, the "OutOfStockImage"
field should be updated automatically to reflect the change.
This can be done by adding the following validation code to the "OutOfStockImage" record link field definition
(the Guid used is the id of the ADAM record containing the out-of-stock image):
| XML |
1
2
3
4
5
6
7
8
9
10
|
<ref:code>
<![CDATA[
adamField.Children.RemoveAll();
if (adamRecord.Fields.GetField<OptionListField>("InStock").Items[0].Definition.Name == "False")
{
adamField.Children.Add(new Guid("7b936956-d8ba-40e1-80a8-9923172a6919"));
}
return true;
]]>
</ref:code>
|
Whenever the value of the "InStock" option list field is changed and the product record is saved, the value of
the "OutOfStockImage" record link field will be updated accordingly. We can also trigger a maintenance job to
resave all product records so all field values are immediately synchronized.
The next step is to add our conditional out-of-stock image to the design template used for paginating our
product records. This is what our template looks like in InDesign (the selected box is where we want to
put our new image):

We need to tag the selected box to use the image which is linked to the product record
through the "OutOfStockImage" record link field. The tagging of the image box is done with our
PageBuilder plug-in for InDesign:

Also, we need to make sure to enable the "Delete when empty" box property so the image box is
removed when paginating product records that have no out-of-stock image linked to them:

Here is a screenshot of the result when paginating two product records, one of them in stock
and the other out of stock:
