rsAddFieldsWithDefaults

This function adds new fields to an existing result set. Unlike rsAddFields, this function provides the ability to specify default values for any fields that are added. Note that rsAddFieldsWithDefaults never over-writes any data in fields that already exist; it only adds new fields to a result set.

Type and Usage

Parameters

The following table lists parameters for the function.

Parameters Description
resultSetName The name of the result set.
newFields A comma-separated list of fields to append to the result set. Any specified fields that already exist in the result set are ignored.
defaultValues An optional comma-separated list of default values that are set for the new fields in each row. Each value in this list corresponds to the new field in the same spot of the list newFields. If you need to set a default value with a comma in it, you can use '^' as a comma. If the defaultValues list is longer or shorter than newFields list, then the function ignores the extra default values or uses the empty string for unspecified default values, respectively.

Output

Nothing.

Example

Adding fields

<$rsCreateResultSet("MyList", "field1,field2,field3")$><$rsAppendRowValues("MyList", "A,B,C,D,E,F")$><$rsAddFieldsWithDefaults("MyList", "field4,field5,field6")$>

In this basic example, we create a result set MyList, fill it with some values, then add three more fields to MyList, without setting default values. The resulting table will look like the following:

field1 field2 field3 field4 field5 field6
A B C      
D E F      

Adding fields with default

<$rsCreateResultSet("MyList", "field1,field2,field3")$><$rsAppendRowValues("MyList", "A,B,C,D,E,F")$><$rsAddFieldsWithDefaults("MyList", "field4,field5,field6", "X,Y,Z")$>

Here we define default values for the new fields. The resulting table will look like the following:

field1 field2 field3 field4 field5 field6
A B C X Y Z
D E F X Y Z

When a field already exists

<$rsCreateResultSet("MyList", "field1,field2,field3")$><$rsAppendRowValues("MyList", "A,B,C,D,E,F")$><$rsAddFieldsWithDefaults("MyList", "field1,field4,field5", "X,Y,Z")$>

In this case, we try and add a field that already exists in MyList. This action is completely ignored, and old field values are preserved. The resulting table will look like the following:

field1 field2 field3 field4 field5
A B C X Y
D E F X Y

Fewer default values specified

<$rsCreateResultSet("MyList", "field1,field2,field3")$><$rsAppendRowValues("MyList", "A,B,C,D,E,F")$><$rsAddFieldsWithDefaults("MyList", "field4,field5,field6", "X,Y")$>

Notice in this example how there are not enough default values in the default value list for all fields. In this case, it just fills in blanks for the unspecified column.

field1 field2 field3 field4 field5 field6
A B C X Y  
D E F X Y  

See Also