Creating Dynamic Data View Add Definition in Apama

Hello Everybody,

I am trying to create a Dataview which has varying number of fields. Using the DataviewAddDefiinition I can add statically the field Values, their names and their types statically. But in the case, if I am not sure in advance about the fields or say if the number of fields are high then what should be the possible way to do this? I tried the following code, but it doesn’t work. Any response in this regard is most welcome. :slight_smile:


    DataViewAddDefinition add := new DataViewAddDefinition;
			 add.dvName := "heatMap8*13";
			 add.dvDisplayName := "heatMap8*13";
			 {
				 integer i :=0;
				 while(i<matArray.size())
				 {
					 add.fieldNames := [i.toString()];
					 add.fieldTypes := ["integer"];
					 i := i+1;
				 }
			 }
			 add.keyFields  := ["keyField"];
			 route add;

Here, I am trying to add the fields equal to the number of elements in matArray .
Thanks in advance,
Mohit

Hi,

In your while loop, you are overwriting the name and type sequence each time, so will end up with only the last field. You’ll want to use append(). Your keyField is also not in the field list -


DataViewAddDefinition add := new DataViewAddDefinition;  
add.dvName := "heatMap8*13";  
add.dvDisplayName := "heatMap8*13";  
{  
integer i :=0;  
while(i<matArray.size())  
{  
     add.fieldNames.append(i.toString());
     add.fieldTypes.append("integer");
     i := i+1;  
}  
}  
add.keyFields  := ["0"];  
route add;

Thanks,
Martin

Hello Martin,

Thanks for the response. It works correctly now.

Regards,
Mohit