Tip>Designer

Dynamically create a new collection as a subset of an existing collection

 

Article #:

0014

Contributor:

Daniel Todes

GF version:

3.05

Applies to:

Collections

Last updated:

September 5, 2001

Description

At run time, create a new collection based on an existing (Dialog) collection.

Explanation

You can dynamically create a new collection, based on the contents of a field in another collection. This is particularly useful for creating a new collection which might be a subset of an existing collection (typically originating from a Dialog).

 

Click here to view a step-by-step example.

In a Dialog you may have a collection of "Parties", one field of which is "Party Role". You then want to create a new collection of Parties, all of whose Party Role is equal to "Limited Guarantor".

To create the collection you would need to insert FillPoints similar to the following in your template (this solution is thanks to Ricky!):

    1. Select the Dialog that contains the original collection:

e.g.,%[^Loan=Dialogs.Select('\Legal Drafting\Loan','A123')]

    1. Create a new object that is a collection:

e.g.%[LimitedGuarantor=createobject('GFDialogObject.dialogobject')]

%[LimitedGuarantor.isacollection=True]

    1. Iterate over the original collection, adding items to the new collection. An item gets added to the new collection based on an appropriate string comparison in the field "Role" of the original collection.

e.g.%[ForEachBlock('P',Loan.Party)]

%[IfTrue((InStr('Limited', P.Role)>0), LimitedGuarantor.Add(P))]

%[EndBlock()]

    1. You are now ready to reference the items in the new collection. If, for example, "Name" is a field in the collection, %[LimitedGuarantor[2].Name] will give the name of the second "Limited Guarantor" in the collection.