Hello !
I am fetching records from an external RDBS (Oracle), making some calculations in an expression rule in Appian, running those records to compare if already present in the local Appian tables, if yes, updates the local record with any changes else inserts a new record altogether. Pretty straightforward. This works as expected.
I am noticing on monitoring the data fetched that there are records retrieved but not inserted into the database. There could be say 2 out of 15 that are missed.
The comparison logic I have is a simple for loop that looks something like below:
if( rule!WS_isNullOrEmpty( ri!rece_cdts ), {}, with( local!parIds_texts: index( ri!rece_cdts, "parId_text", null ), local!existingRece_cdts: if( rule!WS_isNullOrEmpty( local!pars_texts ), {}, rule!WS_getActiveReceByPartyIds( partyIds_texts: local!parIds_texts ) ), a!forEach( items: ri!rece_cdts, expression: with( local!existingReceIndex_int: wherecontains( property( fv!item, "parId_text", null ), touniformstring( property( local!existingRece_cdts, "parId_text", null ) ) ), if( rule!WS_isNullOrEmpty( local!existingReceIndex_int ), /*New Entry*/ fv!item, /*Filter by forward progress and add pk for existing row*/ if( rule!WS_receForwardProgress( currentRece_cdt: fv!item, existingRece_cdt: index( local!existingRece_cdts, local!existingReceIndex_int, null ) ), update( fv!item, "receId_int", index( index( local!existingRece_cdts, local!existingRece_int, null ), "receId_int", null ) ), {} ) ) ) ) ) )
Any suggestions/ideas on where the issue could be? The missing records should have simple been inserted as new rows in my case.
There can't be issues with the forloop function in itself so that makes me wonder if the logic is incorrect.
Thanks in advance !
Discussion posts and replies are publicly visible
It mostly looks correct to me, but the main thing I noticed is that you have an if() statement on line 45 that outputs a value in one scenario and returns an empty list in the other scenario. If the condition is returning false, that could cause some of your rows to not show up in the result - is it possible that is what's happening? Also can you look into that rule (WS_receForwardProgress) to determine if there's some additional logic needed there?
Thanks Peter for your response. The if statement on line 45 has to return empty value if there are no updates that are needed in existing records. That is what the forward (WS_receForwardProgress) rule returns. I re checked and this bit works fine. My records should have been inserted at line 43 and they are not.