Using XML Repeaters
In this tutorial, we will demonstrate how to use the XML Repeater task and the Context Variables it produces to store unique information for a variety of records.
XML Repeater
In this example, we will be working with the following example XML file:
<Company>
<Customers>
<Customer>
<AccountReference>CUST001</AccountReference>
<Name>Customer 1</Name>
<OutstandingBalance>42.00</OutstandingBalance>
</Customer>
<Customer>
<AccountReference>CUST002</AccountReference>
<Name>Customer 2</Name>
<OutstandingBalance>10.00</OutstandingBalance>
</Customer>
<Customer>
<AccountReference>CUST003</AccountReference>
<Name>Customer 3</Name>
<OutstandingBalance>653.00</OutstandingBalance>
</Customer>
</Customers>
</Company>
In this example, we will use the following task settings. Any settings not mentioned can be left at their default values:
Input - The XML file to use. Set this as the name of the XML file.
XPath Query - The XPath query to use for the task. For this example, the XPath would be
Company/Customers/Customer
This gives us access to AccountReference, Name and Outstanding Balance for each record in the XML file as Context Variables.
Next, we can use the Razor Template task and these Context Variables to create personalised text files for emailing. It is important to ensure that the Razor Template is nested within the XML Repeater task. This can be achieved by dragging the Razor Template on top of the XML Repeater task. When successful, you will notice the Razor Template task appears indented.
In this example, we will use the following XML as the template for the Razor template task:
Dear @(Context.Current["Name"]), your outstanding balance is @(Context.Current["OutstandingBalance"]).
Please bring your account up to date at your earliest convenience.
Sincerely,
Test Company
For the Razor Template task, we will use the following task settings. Any settings not mentioned can be left at their default values:
Output File - The file to save successful records to. In this example, we will set this to:
@(Context.Current["AccountReference"]) email.txt
. Please ensure that you click on the ellipsis and tick the "Use Razor Engine" checkbox.Template File - The file containing the template to use. This should be set as the file containing the above Razor Template.
If we run the workflow now, 3 files are created:
- CUST001 email.txt
- CUST002 email.txt
- CUST003 email.txt
Here is an example of the contents of CUST001 email.txt
Dear Customer 1, you're outstanding balance is 42.00.
Please bring your account up to date at your earliest convenience.
Sincerely,
Test Company
This is just a few of the ways Context Variables can be used in an integration, but it should hopefully give you some insight into the other types of operations that can be carried out.