Collection Form Fields
Since we will replace the out-of-the-box BATCHCONSTITUENTPHONE table with the USR_BATCHCONSTITUENTPHONE table within our batch extension, we will need a way to capture the original form fields used to add phone records in addition to a new form field for our BESTTIMETOCALLCODE field. Since the phone records are child records in relation to the parent constituent record, they will represented as a collection of form fields within the batch extension. The batch extension's forms field metadata for the phone records may be found below:
<common:FormFields>
<common:FormField FieldID="EXTPHONES" Caption="PhonesExt" CaptionResourceKey="$$phones">
<common:Collection SequenceFieldID="SEQUENCE">
<common:Fields>
<common:FormField FieldID="ID" Caption="ID" DataType="Guid" Hidden="true" />
<common:FormField FieldID="PHONETYPECODEID" Caption="Phone type" DataType="Guid" CaptionResourceKey="$$phone_type">
<common:CodeTable CodeTableName="PHONETYPECODE" />
</common:FormField>
<common:FormField FieldID="NUMBER" Caption="Phone number" DataType="String" ApplyPhoneFormatting="true" Required="true" CaptionResourceKey="$$phone_number" />
<common:FormField FieldID="COUNTRYID" Caption="Country" DataType="Guid" CaptionResourceKey="$$country">
<common:SimpleDataList SimpleDataListID="C9649672-353D-42E8-8C25-4D34BBABFBBA" />
</common:FormField>
<common:FormField FieldID="ISPRIMARY" Caption="Primary" DataType="Boolean" CaptionResourceKey="$$primary" />
<common:FormField FieldID="SEASONALSTARTDATE" Caption="Seasonal start" DataType="MonthDay" DefaultValueText="0000" CaptionResourceKey="$$seasonal_start" />
<common:FormField FieldID="SEASONALENDDATE" Caption="Seasonal end" DataType="MonthDay" DefaultValueText="0000" CaptionResourceKey="$$seasonal_end" />
<common:FormField FieldID="SEQUENCE" Caption="Sequence" DataType="Integer" Hidden="true" />
<common:FormField FieldID="STARTTIME" Caption="Call after" DataType="HourMinute" CaptionResourceKey="$$call_after" />
<common:FormField FieldID="ENDTIME" Caption="Call before" DataType="HourMinute" CaptionResourceKey="$$call_before" />
<common:FormField FieldID="STARTDATE" Caption="Start date" DataType="Date" CaptionResourceKey="$$start_date" />
<common:FormField FieldID="BESTTIMETOCALLCODE"
Caption="Best Time To Call" DataType="TinyInt"
Description="Best time to call"
DefaultValueText="3">
<common:ValueList>
<common:Items>
<common:Item>
<common:Value>0</common:Value>
<common:Label>Morning</common:Label>
</common:Item>
<common:Item>
<common:Value>1</common:Value>
<common:Label>Midday</common:Label>
</common:Item>
<common:Item>
<common:Value>2</common:Value>
<common:Label>Afternoon</common:Label>
</common:Item>
<common:Item>
<common:Value>3</common:Value>
<common:Label>After Work</common:Label>
</common:Item>
<common:Item>
<common:Value>4</common:Value>
<common:Label>Evening</common:Label>
</common:Item>
</common:Items>
</common:ValueList>
</common:FormField>
</common:Fields>
</common:Collection>
</common:FormField>
</common:FormFields>
In the form fields above, note how the collection field (green highlight) is wrapped with form field (yellow highlight) that has a FieldID attribute equal to EXTPHONES. Also notice within the collection field you find the original phone form fields from the Constituent Batch and an additional BESTTIMETOCALLCODE (blue highlight) for our new custom fields that we are adding with our batch extension.
Within batches, child tables are used to hold child data such as the phone data. A collection of form fields represent the child data for the phone form fields. When data is saved to the batch phone staging table (USR_BATCHCONSTITUENTPHONE) via the add and edit stored procedures or when the data is committed from the staging table to the phone production tables (PHONE and USR_PHONE) the data within the collection of form fields is passed as XML. Each row (collection item) within the form field batch user interface grid is represented as an <Item> element wrapped a parent tag <EXTPHONES>. Note how <EXTPHONES> tag within the XML data corresponds with the value of the FieldID attribute <common:FormField FieldID="EXTPHONES" Caption="PhonesExt" CaptionResourceKey="$$phones"> within the form field metadata above.

Use the CreateChildCollectionFunction Tag within a SQLFunctionSpec
Dealing with the XML passed to and from the database within our batch extension's stored procedures can be tricky to manage. Luckily, we can author a SQLFunctionSpec to retrieve the rows from the staging table and by adding a little additional XML tag; we can prompt the Infinity platform to create some useful functions and stored procedures in addition to the SQLFunctionSpec to manage the XML.
Next, we will author a SQLFunctionSpec that will retrieve the rows from our custom USR_BATCHCONSTITUENTPHONE staging table that our custom batch extension uses. We will include the CreateChildCollectionFunction XML element below the CreateFunctionSQL XML element. Including the CreateChildCollectionFunction element, the platform will generate some helpful and time-saving user-defined functions and stored procedures that help to retrieve and save our collection data that is expressed as XML. When saving data for the batch, data within collection fields such as our phone data is represented as an XML document. This XML document is passed from the batch user interface grid to the appropriate stored procedure for updating or saving of the rows.
When the CreateChildCollectionFunction element is included within the SQLFunctionSpec, the Infinity platform will create two translation user-defined functions that help manage the XML being passed:
-
The FROMITEMLISTXML table valued user-defined function is used to translate incoming XML into a table of phone records. After the XML is translated from XML to a table, we can use the table to update the data within the database.
-
The TOITEMLISTXML scalar-valued user-defined function accepts a unique identifier and retrieves the rows from the batch extension staging table as XML.
In addition, the Infinity platform will create two stored procedures to manage the adding and editing of the XML data to the batch extension staging table.
-
The ADDFROMXML adds data into the batch extension staging table.
-
The UPDATEFROMXML updates data into the batch extension staging table.
These database objects allow a consistent translation between a tabular representation of the results and an XML variable. Below we see an example of a SQLFunctionSpec for our phones data that contains the CreateChildCollectionFunction XML element.
<SQLFunctionSpec
xmlns="bb_appfx_sqlfunction"
xmlns:common="bb_appfx_commontypes"
ID="20332741-2b72-4519-9e0e-1025418a1d0c"
Name="USR_UFN_CONSTITUENTBATCH_GETPHONESWITHSEASONAL"
Description="USR_UFN_CONSTITUENTBATCH_GETPHONESWITHSEASONAL Custom"
Author="Technical Training"
DBFunctionName="USR_UFN_CONSTITUENTBATCH_GETPHONESWITHSEASONAL">
<CreateFunctionSQL>
<![CDATA[
create function dbo.USR_UFN_CONSTITUENTBATCH_GETPHONESWITHSEASONAL
(
@BATCHCONSTITUENTID uniqueidentifier
)
returns table
as
return
(
select
ID,PHONETYPECODEID, NUMBER,
ISPRIMARY, SEQUENCE,STARTTIME,
ENDTIME,STARTDATE,
COUNTRYID,
SEASONALSTARTDATE,
SEASONALENDDATE,
BESTTIMETOCALLCODE
from
dbo.USR_BATCHCONSTITUENTPHONE
where
BATCHCONSTITUENTID = @BATCHCONSTITUENTID
);
] ]>
</CreateFunctionSQL>
<CreateChildCollectionFunction
RootElementName="EXTPHONES"
BaseTableName="USR_BATCHCONSTITUENTPHONE"
ParentIDColumn="BATCHCONSTITUENTID"/>
</SQLFunctionSpec>
Looking at the CreateChildCollectionFunction XML element above, you must provide three attributes.
-
RootElementName provides the name to identify the root element of the XML document that represents the data from the collection field within the Batch Extension Spec.
-
BaseTableName is the base table from which the collection of data as defined by the collection form field element within the BatchTypeExtensionSpec.
-
ParentIDColumn is the parent ID column in the base table. In our case, the base table is USR_BATCHCONSTITUENTPHONE and it contains a parent ID of BATCHCONSTITUENTID that relates the table back to its parent table: BATCHCONSTITUENT.
When the spec is loaded, the following database objects are created:
