Best of Support

Creating an array

Issue

Is there a way to create an array, then store objects (text) in it, and then pull the text back out to put it in a document?

Solution:

Firstly, in GhostFill it is possible to dynamically create an array (collection), and store text for later retrieval.

 

For example:

%[MyArray=CreateObject('gfdialogobject.dialogobject')]

%[MyArray.isacollection=true]

%[MyArray.add("Fred")]

%[MyArray.add("Jim")]

%[MyArray.add("Bob")]

%[MyArray.count] will then return the number of items in the collection.

%[MyArray[2]] will return a specific item.

 

Iterating over all items in the resultant array/collection can then be done in one of two ways:

 

Option 1 Example (using "ForEachBlock"):

%[ForEachBlock("x",myarray)]

%[x] %[EndBlock]

 

Option 2 Example (using "RepeatBlockWhile"):

%[i=1]%[RepeatBlockWhile(i<=myarray.count)]

%[myarray[i]]%[i=i+1]%[EndBlock]

 

In terms of your specific query, it is not clear to us where the custom fields that you want to report on are being stored: are they in a selection of files (matters), or a selection of contacts?  Note that in Amicus Assembly, the selected matters or selected contacts are already stored as a collection aa.selectedmatters or aa.selectedcontacts.

 

Which means in your template you could do something directly as follows:

%[i=1]

Flat Fee Service

Flat Fee Rate

%[RepeatblockWhile(i<=aa.selectedmatters.count)]

%[aa.selectedmatters[i].customfield("Flat Fee Service")]

%[aa.selectedmatters[i].customfield("Flat Fee Rate")]%[i=i+1]%[EndBlock]

 

Alternatively, you could have created the arrays up front as follows:

%[Service=CreateObject('gfdialogobject.dialogobject')]%[Service.isacollection=true] %[Rate=CreateObject('gfdialogobject.dialogobject')]%[Rate.isacollection=true] %[ForEachBlock("x",aa.selectedmatters)]%[service.add(x.customfield("Flat Fee Service"))]%[EndBlock]

%[ForEachBlock("x",aa.selectedmatters)]%[rate.add(x.customfield("Flat Fee Rate"))]%[EndBlock]

 

And then:

%[i=1]

Flat Fee Service

Flat Fee Rate

%[RepeatblockWhile(i<=service.count)]%[service[i]]

%[rate[i]]%[i=i+1]%[EndBlock]