Can I refrence a varable dynamicly?

I hope the topic description make sense. I am working on a script that will be used to export to CSV or JSON. The user selects what one they want and the script loops and generates it. But I would like to make this as script easy to use for other reports with different fields.

What I came up with works but has the tedium of needing multiple section updated for each field. Is there a way to make this code work without needing to change $data1 to $data2 etc.? my original thinking was to have the dataNumber to be used for data as well as column. But I do not know how to reference a variable like $data & dataNumber or if anything like that is possible.

Let ( [ 
	dataNumber	= $dataNumber +1
;	data		= $Data1
;	column		= GetValue ( $HeaderList; dataNumber )
;	recordNumber	= Get(RecordNumber)
	] ; 

	JSONSetElement ( $json ; "[" & recordNumber & "]." &  column ; data ; JSONString )

	)

If I can make this work with only one Set Variable line needing to be edited per data point exported it would meet my needs. Well even as is it works but I would love to hear feedback if anyone has a better suggestion.

How about $Data[dataNumber]?

2 Likes

That sounds like exactly what I was looking for. I did not know you could do a repeating variable. It also never occurred to me to look up set variable, it seemed like such a simple script step.

Thanks for the help.