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
}
You can see above in my add statement I am updating two fields on each row...or trying to.
Solved! Go to Solution.
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]
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]