I have a feature class that is the result of a spatial join between a group of Credit_Recipient (RecClmNum) and Credit_Allocation (AllocClmNum) land parcels. The join essentially associates Credit_Allocation parcels that are within a given buffer of the Credit_Recipient parcels. This means I may have 1, 2, or X number of Credit_Allocation parcels associated to a single Credit_Recipient parcel. I have created a new table into which I want to add each Credit_Recipient parcel number, the credit value (CorrRecCreVal) it needs to receive, and the Credit_Allocation parcel number from which it will receieve the value. The calculation for the credit allocation is a straight subtraction of the required credit value CorrRecCreVal) from the available credit (CorrAllocCreVal) in the allocation parcel. The code below does what I want but only on the first row (and only if I use the "next()" parameter). I need the script to repeat the code from the "SearchCursor.da" point. If I use the "for row in cursor" option it doesn't do the correct calculation (basically it does do it, but regardless of whether the Credit_Recipient has or hasn't received an allocation).
sourceFC <SPAN class="operator token">=</SPAN> <SPAN class="string token">"UpdatedRecipientClaims"</SPAN>
sourceFieldsList <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="string token">"RecClmNum"</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">"TransferredValue"</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="comment token"># use list comprehension to build a dictionary from a da SearchCursor.</SPAN>
valueDict <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">{</SPAN>r<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="punctuation token">(</SPAN>r<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">for</SPAN> r <SPAN class="keyword token">in</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>da<SPAN class="punctuation token">.</SPAN>SearchCursor<SPAN class="punctuation token">(</SPAN>sourceFC<SPAN class="punctuation token">,</SPAN>sourceFieldsList<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">}</SPAN>
sourceFC2 <SPAN class="operator token">=</SPAN> <SPAN class="string token">"ActualTbleCopy2SortedAllocationClaims"</SPAN>
sourceFieldsList2 <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="string token">"AllocClmNum"</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">"CorrAllocCreVal"</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="comment token"># Use list comprehension to build a dictionary from a da SearchCursor</SPAN>
valueDict2 <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">{</SPAN>r2<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="punctuation token">(</SPAN>r2<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">for</SPAN> r2 <SPAN class="keyword token">in</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>da<SPAN class="punctuation token">.</SPAN>SearchCursor<SPAN class="punctuation token">(</SPAN>sourceFC2<SPAN class="punctuation token">,</SPAN>sourceFieldsList2<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">}</SPAN>
SearchFC <SPAN class="operator token">=</SPAN> <SPAN class="string token">"RecipientBufferClaims"</SPAN>
SearchFieldsList <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="string token">"RecClmNum"</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">"CorrRecCreVal"</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">"AllocClmNum"</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="keyword token">with</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>da<SPAN class="punctuation token">.</SPAN>SearchCursor<SPAN class="punctuation token">(</SPAN>SearchFC<SPAN class="punctuation token">,</SPAN>SearchFieldsList<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> srchCursor<SPAN class="punctuation token">:</SPAN>
srchRow <SPAN class="operator token">=</SPAN> srchCursor<SPAN class="punctuation token">.</SPAN>next<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token">#for srchRow in srchCursor:</SPAN>
<SPAN class="comment token"># store the Join value SearchCursor in the Key... variable</SPAN>
KeyRecipientClaim <SPAN class="operator token">=</SPAN> srchRow<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN>
KeyRecipientCredit <SPAN class="operator token">=</SPAN> srchRow<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN>
KeyAllocationClaim <SPAN class="operator token">=</SPAN> srchRow<SPAN class="punctuation token">[</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="comment token"># store the field values in a variable for the insert cusor</SPAN>
rowValues <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">(</SPAN>srchRow<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN>srchRow<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="comment token"># if the recipient claim (KeyRecipientClaim) is not in the returned variable</SPAN>
<SPAN class="comment token"># rowValues, then insert it into the table. If I use the "for srchRow in</SPAN>
<SPAN class="comment token"># srchCursor:" instead of "srchRow = srchCursor.next()" it calculates on all the</SPAN>
<SPAN class="comment token"># RecipientClaims regardless of whether they have received a credit or not.</SPAN>
<SPAN class="keyword token">if</SPAN> KeyRecipientClaim <SPAN class="operator token">not</SPAN> <SPAN class="keyword token">in</SPAN> sourceFC<SPAN class="punctuation token">:</SPAN>
insrtCurs <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>da<SPAN class="punctuation token">.</SPAN>InsertCursor<SPAN class="punctuation token">(</SPAN>sourceFC<SPAN class="punctuation token">,</SPAN>sourceFieldsList<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">for</SPAN> row <SPAN class="keyword token">in</SPAN> rowValues<SPAN class="punctuation token">:</SPAN>
insrtCurs<SPAN class="punctuation token">.</SPAN>insertRow<SPAN class="punctuation token">(</SPAN>row<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">del</SPAN> insrtCurs
<SPAN class="keyword token">del</SPAN> row
query <SPAN class="operator token">=</SPAN> <SPAN class="string token">""" "AllocClmNum" = '%s'"""</SPAN><SPAN class="operator token">%</SPAN>KeyAllocationClaim
arcpy<SPAN class="punctuation token">.</SPAN>SelectLayerByAttribute_management<SPAN class="punctuation token">(</SPAN>sourceFC2<SPAN class="punctuation token">,</SPAN><SPAN class="string token">"NEW_SELECTION"</SPAN><SPAN class="punctuation token">,</SPAN>query<SPAN class="punctuation token">)</SPAN>
upCurs <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>da<SPAN class="punctuation token">.</SPAN>UpdateCursor<SPAN class="punctuation token">(</SPAN>sourceFC2<SPAN class="punctuation token">,</SPAN>sourceFieldsList2<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">for</SPAN> upRow <SPAN class="keyword token">in</SPAN> upCurs<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">if</SPAN> upRow<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">>=</SPAN> <SPAN class="number token">15000</SPAN><SPAN class="punctuation token">:</SPAN>
NewAllocCredVal <SPAN class="operator token">=</SPAN> upRow<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> upRow<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">-</SPAN> KeyRecipientCredit
<SPAN class="keyword token">if</SPAN> NewAllocCredVal <SPAN class="operator token">>=</SPAN> <SPAN class="number token">15000</SPAN><SPAN class="punctuation token">:</SPAN>
upCurs<SPAN class="punctuation token">.</SPAN>updateRow<SPAN class="punctuation token">(</SPAN>upRow<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">del</SPAN> upCurs
<SPAN class="keyword token">del</SPAN> upRow
arcpy<SPAN class="punctuation token">.</SPAN>SelectLayerByAttribute_management<SPAN class="punctuation token">(</SPAN>sourceFC2<SPAN class="punctuation token">,</SPAN><SPAN class="string token">"CLEAR_SELECTION"</SPAN><SPAN class="punctuation token">)</SPAN>
query2 <SPAN class="operator token">=</SPAN> <SPAN class="string token">""" "RecClmNum" = '%s'"""</SPAN><SPAN class="operator token">%</SPAN>KeyRecipientClaim
arcpy<SPAN class="punctuation token">.</SPAN>SelectLayerByAttribute_management<SPAN class="punctuation token">(</SPAN>sourceFC<SPAN class="punctuation token">,</SPAN><SPAN class="string token">"NEW_SELECTION"</SPAN><SPAN class="punctuation token">,</SPAN>query2<SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>CalculateField_management<SPAN class="punctuation token">(</SPAN>sourceFC<SPAN class="punctuation token">,</SPAN><SPAN class="string token">"AllocClmNum"</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">'KeyAllocationClaim'</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">"PYTHON_9.3"</SPAN><SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>SelectLayerByAttribute_management<SPAN class="punctuation token">(</SPAN>sourceFC<SPAN class="punctuation token">,</SPAN><SPAN class="string token">"CLEAR_SELECTION"</SPAN><SPAN class="punctuation token">)</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></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>