Missing records during an a!forEach() iteration and insert into db via data store entity

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