Split spool (complex key)

Split spool (complex key)

A spooled file can be split into smaller files depending on the contents e.g. to split up a larger spooled file with many invoices into individual invoices.

If the other spooled file split functions are not enough, then you can consider this workflow component: Split spool (complex key).

 

This advanced, converted workflow component has these parameters:

    


 

Subset expression

This is a page selection criterion, that you can use in order to select specific pages of the input spooled file. This is matched with the key expression, so that the key(s) are extracted on pages, that match the condition for the subset. If you have loaded a sample spooled file (which is recommended) you can use the magnifying glass to select the spooled file data for the condition.

You can add multiple sets of conditions and keys with the add more icon.

 

Key expression

This is combined with the subset above in the way that if the condition in the subset expression is true, then the key value is found via this expression. In the example above we search for 'Invoice No' in line 13 and if it is found then the invoice number is extracted in line 13, but if the text 'Invoice No' is found in line 14, then the invoice number is extracted from line 14.

 

Action for pages without key

With this option you can decide what should happen with pages, where no subset expression is true. The possible values are:

Add to current document: With this value the pages are added to the previous key. In this way you can split up documents where the key (e.g. invoice number) is only found on the first page of each document.

Throw away: With this value all pages without a key are not included in the splitted output files. This can be considered, if you want to remove some pages, that are not really needed.

 

Save key value as

Here you can state a workflow variable, that should receive the value found in the spooled file as key value position. Notice, that you should write the variable without a dollar sign as above. After the split spool component, you can e.g. create PDF files, that are using the variable as a part of the PDF file name or path.

 

Grouping rule

The field "Grouping rule (XPath for group name)" can be used to specify a rule for grouping pages. This can be used to group the split pages together in a smaller number of spooled files.

Notes
The grouping option for the split components is not supported for the input type, From IBM i output queue (Stream). 

The rule is an XPath expression that must output the name of the group that the split pages should be placed in.

For instance, say you have three pages with key values 1001, 1002, 1003. If you do not specify a grouping rule, then this will result in 3 spooled files after the split.

If you saved your variable as "customerNo", then you can create a grouping rule like this:

if (number($customerNo) < 1003) then 'g1' else 'g2'

 

Now the output will be only two spooled files instead of three, one containing the pages with key value 1001 and 1002, another containing the page with key value 1003.

The name of the spooled file's group can be found as the workflow variable, "interform.spooled.groupName".

 

Example of use: You can find an example of how you can implement a split definition with variables in the section, Example: Use variables for naming output files.


Example: Collect all pages, where a line contains both the text 'DREXID' in position 3 to 8 and 'S' in position 30. Search for a line with this contents from line 54 to 59.

If you want to collect all of these pages into a single Splf file, then you can use the Split spool (complex key) with the settings below:

1. The simple, tedious solution
This can be done in a couple of ways. Here is a bit tedious, but simple solution:


For the subset expression we have selected each and every line and added test for all. We use the key and grouping to collect all the pages into a single output file. If that is not needed, then the key and grouping can be left out. The solution works but it is a bit tedious to add conditions for each and every spooled file line, so the alternative below can be considered.

2. The shorter, more advanced solution


The subset expression is:
count(//page[1]/line[position()>=54 and position()<=59 and substring(text(),30,1)='S' and substring(text(),3,6)='DREXID'])>0
This expression makes use of the fact, that the spooled file in InterFormNG2 is actually stored as an XML file, where there is a page node for each spooled file page and inside of the page there is a line node for every line in that page (also for empty lines). So that means, that we can use the position() function to identify the line number of any line.  The line node is follow by [], which means that we only want to include line nodes that match the expression, that is added into the [].

The expression counts all line nodes, which has a line number (position), that is larger or equal to 54 and the line number also must be less or equal to 59. This selection ignores any lines outside this range.

Next the function: substring(text(),30,1)='S' is used. It retrieves the value of the current line (with the function text()) and it extracts the character in position 30 and this character must be 'S'.

Finally the text of the current line in position 3 to 8 is compared to 'DREXID'. The compare text is 6 characters long hence the expression substring(text(),3,6)='DREXID'.

    • Related Articles

    • Split spool (fixed key position)

      If you want InterFormNG2 to process spooled files, that contains multiple documents e.g. multiple invoices within a single spooled file (e.g. generated by a batch invoice run), then you may want to split up the spooled file into multiple output PDF ...
    • Split spool (variable key position)

      As the split spooled file (fixed key position) component above, this component can be used to split a spooled file based on a key value. However, in this case the key value can be in variable positions on the page. You just need to be able to find ...
    • Spooled file split

      You might want to split up spooled files during InterFormNG2 processing. The reason might be, that the input spooled file may contain multiple documents (e.g. invoices), and that you want to create one PDF file (or email) for each invoice. There are ...
    • Split XML

      This advanced converter workflow component can split up an XML in the payload of the current workflow. The subtree of this workflow component is executed for each splitted XML. A similar component, which is also able to transform the splitted files, ...
    • Delayed email cancel key

      The Delayed email cancel key component is used together with these workflow components: Cancel delayed email. Use this component to cancel a delayed email. PDF Delayed email. This defines a delayed email. Send emails from delay queue. This sends out ...