# Can I refrence a varable dynamicly?

**URL:** <https://the.fmsoup.org/t/can-i-refrence-a-varable-dynamicly/4129>\
**Category:** Questions\
**Tags:** scripting\
**Created:** [May 21, 2024, 12:22am UTC](https://the.fmsoup.org/t/can-i-refrence-a-varable-dynamicly/4129 "2024-05-21T00:22:21Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Susurrus](https://yyz2.discourse-cdn.com/flex030/user_avatar/the.fmsoup.org/susurrus/32/472_2.png) [@Susurrus](https://the.fmsoup.org/u/Susurrus)\
**Post date:** [May 21, 2024, 12:22am UTC](https://the.fmsoup.org/t/can-i-refrence-a-varable-dynamicly/4129/1 "2024-05-21T00:22:21Z")

</div>

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.

```auto
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.

---

<div class="post-metadata">

**Author:** ![bdbd](https://yyz2.discourse-cdn.com/flex030/user_avatar/the.fmsoup.org/bdbd/32/620_2.png) [@bdbd](https://the.fmsoup.org/u/bdbd)\
**Post date:** [May 21, 2024, 1:01am UTC](https://the.fmsoup.org/t/can-i-refrence-a-varable-dynamicly/4129/2 "2024-05-21T01:01:51Z")

</div>

How about $Data[dataNumber]?

---

<div class="post-metadata">

**Author:** ![Susurrus](https://yyz2.discourse-cdn.com/flex030/user_avatar/the.fmsoup.org/susurrus/32/472_2.png) [@Susurrus](https://the.fmsoup.org/u/Susurrus)\
**Post date:** [May 21, 2024, 1:57am UTC](https://the.fmsoup.org/t/can-i-refrence-a-varable-dynamicly/4129/3 "2024-05-21T01:57:19Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Kirk](https://yyz2.discourse-cdn.com/flex030/user_avatar/the.fmsoup.org/kirk/32/2197_2.png) [@Kirk](https://the.fmsoup.org/u/Kirk)\
**Post date:** [January 15, 2025, 4:27pm UTC](https://the.fmsoup.org/t/can-i-refrence-a-varable-dynamicly/4129/4 "2025-01-15T16:27:52Z")

</div>

You can concatenate multiple values into a single variable.

Repeating fields/Variable are not recommended for real data due to obscurity of content, limitations on presentation and complexity of coding.

---

<div class="post-metadata">

**Author:** ![Kirk](https://yyz2.discourse-cdn.com/flex030/user_avatar/the.fmsoup.org/kirk/32/2197_2.png) [@Kirk](https://the.fmsoup.org/u/Kirk)\
**Post date:** [March 5, 2025, 9:17pm UTC](https://the.fmsoup.org/t/can-i-refrence-a-varable-dynamicly/4129/5 "2025-03-05T21:17:20Z")

</div>

You could also create a layout with the set of fields you want and use the “execute FileMaker dataAPI” script step to output directly to JSON
