Select to view content in your preferred language

Arcade: multiple values in an array (arrays in an array).

1582
1
Jump to solution
02-11-2021 08:38 AM
TL2
by
Frequent Contributor

This script adds a number of rows to a table on insert of another table.  It uses an array to updated a field value when these rows are entered.  I would like to enter multiple field values instead of just one, which works as seen below.  My first script is what works with one value, using a simple array.  My second script is what I am trying to accomplish but I am not sure how to format my row.

 

var rowid = $feature.uniquerowid
var myArray = ['value1','value2','value3']
var counter = 0
if(IsEmpty($feature.inspect_date)){
for (var os in myArray){
myArray[counter] = 
                     {
       "attributes": {
             "parentrowid": rowid,
             "q_2control": myArray[os],
             "number": counter
                            }
                        }
                        counter++
                        }
   return {
"result": rowid,
"edit": [{
    "className": "featureClass",
    "adds": myArray
              }]
           }

}
else {
return rowid
}

 

I would like to enter multiple fields for each row added.  Something like this:

var rowid = $feature.uniquerowid
var myArray = [['value1A,'value1B'],['value2A,'value2B'],['value3A,'value3B']]
var counter = 0
if(IsEmpty($feature.inspect_date)){
for (var os in myArray){
myArray[counter] = 
                     {
       "attributes": {
             "parentrowid": rowid,
             "q_2control": myArray[os[a]],
             "choice": myArray[os[b]]
             "number": counter
      
                            }
                        }
                        counter++
                        }
   return {
"result": rowid,
"edit": [{
    "className": "featureClass",
    "adds": myArray
              }]
           }

}
else {
return rowid
}

 

@XanderBakker 

You can see above in my add statement I am updating two fields on each row...or trying to. 

0 Kudos
1 Solution

Accepted Solutions
XanderBakker
Esri Esteemed Contributor

Hi @TL2 ,

Since you don't have a variable a and b, the code will fail. You can use the indexes (0 and 1) to extract the "a" and "b" values:

 

             "q_2control": myArray[os][0],
             "choice": myArray[os][1]

 

View solution in original post

1 Reply
XanderBakker
Esri Esteemed Contributor

Hi @TL2 ,

Since you don't have a variable a and b, the code will fail. You can use the indexes (0 and 1) to extract the "a" and "b" values:

 

             "q_2control": myArray[os][0],
             "choice": myArray[os][1]