Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.

Reusing Arrays in Forms

Avatar

Former Community Member
Is it possible to create an array when a button is clicked, then reference that array later in the form? Can the array be referenced somwhere else in the form?
2 Replies

Avatar

Former Community Member
Troye,



You can create an array on the click event of the button with the following code:



arrayTesy = new Array("1","2","3");



You can reference the array like the following:



arrayTesy[3];

(refers to the fourth occurrence of array arrayTest)



Hope this helps,



Catherine

Avatar

Former Community Member
Hi Troye,



you could try something like this as well:



Create a script object, eg FormScripts.

Put the following functions there:



var myArray = new Array();



function setArrayValue(nIndex, someValue) {

myArray[nIndex] = someValue;

}



function getArrayValue(nIndex) {

return myArray[nIndex];

}



Then, in an event in your form you would have code something like:



FormScripts.setArrayValue(0,"First Value");

FormScripts.setArrayValue(1,"Second Value");

FormScripts.setArrayValue(2,"Third Value");



And, in another event you can access the array values with:



var myValue = FormScripts.getArrayValue(1);

app.alert(myValue);