Professional > Data management scripting > Data Management reference > Data Management functions > CopyGrid
 
CopyGrid
Transfers data from SourceGrid to DestinationGrid (used for OnNextCase events). SourceGrid contains the originally collected data, while DestinationGrid stores the copied data. IterationFilter restricts iterations copied for DestinationGrid.
Syntax
CopyGrid(SourceGrid, DestinationGrid, IterationFilter)
Parameters
SourceGrid
Type: Object
Grid question
DestinationGrid
Type: Object
Grid question
IterationFilter
Type: Categorical
Categorical for iteration filter
(return)
Type: Boolean
True if copy is successful
Notes
If IterationFilter is null, data transfer from SourceGrid to DestinationGrid will be processed according to the iterations for DestinationGrid, otherwise according to the iterations in IterationFilter.
There may be some iterations or sub-questions in DestinationGrid that do not exist in SourceGrid. This function only copies the common iterations and sub-questions in DestinationGrid and SourceGrid.
Example
CopyGrid(Loop1, LoopForCopy, Null)
The definitions for Loop1 and LoopForCopy are as follows:
Loop1 - loop
{
A -,
B -,
C -,
D -
} fields -
(

Q1 "LikeOrNot" categorical [1..1]
{
Like -,
Dislike -
};
Q2 Text[20];
Q3 Long[1..5];

) expand grid;

LoopForCopy - loop
{
B -,
A -,
D -
} fields -
(
Q2 Text[20];
Q1 "LikeOrNot" categorical [1..1]
{
Like -,
Dislike -
};

) expand grid;
For the current record, the value for Loop1 is as follows:
LevelID
Q1
Q2
Q3
{A}
{ Dislike }
I am testing
2
{B}
{Like}
I am
2
{C}
{Dislike}
I
3
{D}
{Like}
I am t
4
The value for LoopForCopy is as follows:
LevelID
Q2
Q1
{A}
I am testing
{ Dislike }
{B}
I am
{Like}
{D}
I am t
{Like}
CopyGrid(Loop1, LoopForCopy, {A,B})
Based on the above value for Loop1, the value for LoopForCopy will be as follows:
LevelID
Q2
Q1
{A}
I am testing
{ Dislike }
{B}
I am
{Like}
Performance note
CopyGrid can transfer data between grids for many scenarios. The grid may contain any type of question (single response, compound, block, nested grid, and so on). Use the following script example for better performance when the grid being copied has only one nested question:
For Each Iteration In Grid1
   Grid1_Copy[Iteration.QuestionName].Item[0].Response =
      Iteration.Item[0]
Next
See also
Data Management functions