a!buttonWidgetSubmit( skipValidation: true, style: "DESTRUCTIVE", confirmMessage: "Rejecting this batch will cancel all transactions from being processed and this action cannot be reversed. Do you want to proceed?", label: "REJECT", saveInto: { if( rule!CAS_canBatchBeCompleted(batchId: ri!deposit.depositId), { a!save(ri!buttonValue, cons!CAS_BUTTON_CANCEL_BATCH), if( rule!GBL_isBlank(ri!deposit.depositId), {}, { a!forEach( items: ri!sourceCashEntries, expression: if(ri!sourceCashEntries.allocationTypeId = 5, { a!save(ri!sourceCashEntries.suspenseIsOpen, true), a!save(ri!sourceCashEntries.isAdjusted, false) }, /*Added suspense is open flag for non suspense allocation type*/ {a!save(ri!sourceCashEntries.suspenseIsOpen, false), a!save(ri!sourceCashEntries.isAdjusted, false) } ) ), a!save(ri!deposit.statusId, cons!CAS_REFERENCE_DATA_ID_BATCH_STATUS_CANCELLED), a!save(ri!deposit.lastUpdatedBy, loggedInUser()), a!save(ri!deposit.lastUpdateDatetime, now()), if( rule!GBL_isEmpty(ri!auditLog), a!save( ri!auditLog, rule!CAS_createAuditHistoryObject( recordType: cons!CAS_RECORD_TYPE_ID_BATCH, recordId: ri!deposit.depositId, initiator: loggedInUser(), eventTimestamp: now(), actionTypeId: cons!CAS_ACTION_TYPE_BATCH_CANCELLED ) ), a!save( ri!auditLog, append( ri!auditLog, rule!CAS_createAuditHistoryObject( recordType: cons!CAS_RECORD_TYPE_ID_BATCH, recordId: ri!deposit.depositId, initiator: loggedInUser(), eventTimestamp: now(), actionTypeId: cons!CAS_ACTION_TYPE_BATCH_CANCELLED ) ) ) ), a!writeToMultipleDataStoreEntities( valuesToStore: { a!entityData( entity: cons!CAS_DSE_CASH_DEPOSIT, data: ri!deposit ), a!entityData( entity: cons!CAS_DSE_AUDIT_HISTORY, data: ri!auditLog ) ,a!entityData( entity: cons!CAS_DSE_CASH_ENTRY, data: ri!sourceCashEntries ) }, onSuccess: { a!save(ri!isError, false), a!save( ri!deposit, fv!storedValues[1].data ), a!save( ri!auditLog, fv!storedValues[2].data ) ,a!save( ri!sourceCashEntries, fv!storedValues[3].data ) }, onError: { a!save( ri!isError, true ), a!save( ri!errorText, "There was an error cancelling the batch. Please try again." ) } ) } ) }, { a!save(ri!isError, true), a!save(ri!errorText, "This batch has already been completed") } ) } )
Discussion posts and replies are publicly visible
Just with a quick glance - you're looping over the ri!sourceCashEntries array using a!forEach, but then inside your forEach, instead of referring to the current item of the array using fv!item, you're having your a!save() calls act directly on ri!sourceCashEntries (most notably, acting as if it were not an array). Please try replacing "ri!sourceCashEntries." with "fv!item." on lines 25 and 26, and see if the behavior gets closer to what your expectations were.
Thanks, Mike for your insight. Tried replacing it to fv!item however, the isadjusted is still not being updated to false
I suggest restructuring your saveInto. Instead of looping over the array and trying to execute multiple (maybe dozens?) of individual saves within it, call the save once and use the a!forEach() function to assemble the altered array you're after. Until 20.2 is out you'll need to use the "updateDictionary" plug-in function to accomplish this, but it shouldn't be a problem hopefully.
a!save( ri!sourceCashEntries, a!forEach( ri!sourceCashEntries, if( fv!item.allocationTypeId = 5, updateDictionary( fv!item, { suspenseIsOpen: true(), isAdjusted: false() } ), /* .... etc */ ) ) )