I am having trouble with for loops. This example prints out the second item in the array.
var array <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="string token">"RC-22p"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"RC-22e"</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">;</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">for</SPAN><SPAN class="punctuation token">(</SPAN>var <SPAN class="number token">c</SPAN> <SPAN class="operator token">in</SPAN> array<SPAN class="punctuation token">)</SPAN> {
var invoice <SPAN class="operator token">=</SPAN> array<SPAN class="punctuation token">[</SPAN><SPAN class="number token">c</SPAN><SPAN class="punctuation token">]</SPAN>
}
<SPAN class="keyword token">return</SPAN> invoice<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>The result is RC-22e.
I am trying to loop through an array, look up the corresponding globalid and update that related record. When I run my code the first item in the array is completed, but it stops after the first one, it doesn't loop... How can I get my for loop to loop when my return is updating another feature class?
var array <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="string token">"RC-22H"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"RC-22I"</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">;</SPAN>
var pipe <SPAN class="operator token">=</SPAN> <SPAN class="string token">""</SPAN><SPAN class="punctuation token">;</SPAN>
var invoice <SPAN class="operator token">=</SPAN> <SPAN class="string token">""</SPAN><SPAN class="punctuation token">;</SPAN>
var i <SPAN class="operator token">=</SPAN> <SPAN class="string token">""</SPAN><SPAN class="punctuation token">;</SPAN>
var <SPAN class="number token">c</SPAN> <SPAN class="operator token">=</SPAN> <SPAN class="string token">""</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="comment token">//loop</SPAN>
<SPAN class="keyword token">for</SPAN><SPAN class="punctuation token">(</SPAN>var <SPAN class="number token">c</SPAN> <SPAN class="operator token">in</SPAN> array<SPAN class="punctuation token">)</SPAN>
{
<SPAN class="comment token">//lookup globalid based on item in array</SPAN>
var pipe <SPAN class="operator token">=</SPAN> FeatureSetByName<SPAN class="punctuation token">(</SPAN>$datastore<SPAN class="punctuation token">,</SPAN><SPAN class="string token">"SUDOECMS.DBO.doe_EAP_pipelineabandon"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
var invoice <SPAN class="operator token">=</SPAN> filter<SPAN class="punctuation token">(</SPAN>pipe<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"invoice = '"</SPAN> <SPAN class="operator token">+</SPAN> array<SPAN class="punctuation token">[</SPAN><SPAN class="number token">c</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">"'"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
var i <SPAN class="operator token">=</SPAN> <SPAN class="token function">first</SPAN><SPAN class="punctuation token">(</SPAN>invoice<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="comment token">//if feature value is q_1, update the other record </SPAN>
<SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>$feature<SPAN class="punctuation token">.</SPAN>q_x <SPAN class="operator token">=</SPAN><SPAN class="operator token">=</SPAN> <SPAN class="string token">'q_1'</SPAN><SPAN class="punctuation token">)</SPAN>{
<SPAN class="keyword token">return</SPAN> {
<SPAN class="string token">"result"</SPAN>: $feature<SPAN class="punctuation token">.</SPAN>q_x<SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">'edit'</SPAN>: <SPAN class="punctuation token">[</SPAN>{
<SPAN class="string token">'className'</SPAN>: <SPAN class="string token">'SUDOECMS.DBO.doe_EAP_pipelineabandon'</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">'updates'</SPAN>: <SPAN class="punctuation token">[</SPAN>{
<SPAN class="string token">'globalID'</SPAN>: i<SPAN class="punctuation token">.</SPAN>GlobalID<SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">'attributes'</SPAN>: {
<SPAN class="string token">'q_1'</SPAN>: $feature<SPAN class="punctuation token">.</SPAN><SPAN class="keyword token">status</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">'q_1comments'</SPAN> : $feature<SPAN class="punctuation token">.</SPAN>q_xcomments<SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">'q_1rank'</SPAN> : $feature<SPAN class="punctuation token">.</SPAN>q_xrank
}
}<SPAN class="punctuation token">]</SPAN>
}<SPAN class="punctuation token">]</SPAN>
}
}
<SPAN class="comment token">//stops here but I want to repeat, it only updates the other record based on RC-22H, it does not update RC-22I. </SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>Xander Bakker