Mitech Preloader

Document per Repeated Item – with Filter

Cookbook

Document per Repeated Item – with Filter

Please see the recipe Document per Repeated Item for an introduction to this concept.

Now, following on from the above discussion, suppose we need a separate document for each of the sureties, but only if a particular surety has a net asset value of $100,000 or more.  The template itself will remain unchanged except that a SetMultipleDocumentFilter command will be applied to it.  Here follows the original example, slightly modified and incorporating with this new command:

I, «Surety[$SuretyNumber]/SuretyFirstNames» «Surety[$SuretyNumber]/SuretySurname» (Born on «FormatDate(Surety[$SuretyNumber]/SuretyDOB, “dd MMMM yyyy”)») hereby declare blah blah.
blah

My net assets are $«FormatNumber(Surety[$SuretyNumber]/NetAssets)»

«SetMultipleDocumentFilter(NetAssets >= 100000)»

Signed: «Surety[$SuretyNumber]/SuretyFirstNames» «Surety[$SuretyNumber]/SuretySurname»

This would result in one document being produced for each surety, but only if that particular surety’s net asset value is greater than $100,000.

This is fine so long as the minimum net asset value is always going to be $100,000.  But suppose you want the user (i.e. the person running the template) to be able to set this minimum value from one application to another.  You would then have a data element called something like MinimumAssetValue which is captured in the interview outside the scope of the sureties, and the resulting template snippet would look like this:

«CaptureDataElement(MinimumAssetValue,Decimal)»

I, «Surety[$SuretyNumber]/SuretyFirstNames» «Surety[$SuretyNumber]/SuretySurname» (Born on «FormatDate(Surety[$SuretyNumber]/SuretyDOB, “dd MMMM yyyy”)») hereby declare blah blah.
blah

My net assets are $«FormatNumber(Surety[$SuretyNumber]/NetAssets)»

«SetMultipleDocumentFilter(NetAssets >= ../MinimumAssetValue)»

Signed: «Surety[$SuretyNumber]/SuretyFirstNames» «Surety[$SuretyNumber]/SuretySurname»

You will notice the ../ before MinimumAssetValue. This is because the scope of the data elements in the condition is by default the repeating data element – in this case Surety. In order to reference a data element higher in the XML hierarchy, the ../ notation is used. A fairly comprehensive discussion of this is contained in the recipe Working with repeated elements under the heading Referencing Non-repeating elements within a ForEach block.