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
Interesting code ....
I implement things like this in different way.
Have an expression which takes all necessary input, does some magic and creates a list of entityData items. You would call this expression directly at valuesToStore.
This way you separate this complex logic from the UI and keep it maintainable.
Unknown said:Have an expression which takes all necessary input, does some magic and creates a list of entityData items. You would call this expression directly at valuesToStore.
Also if you store your magic'd array in a local variable, it's 100x easier to troubleshoot as you can just see the array values in the local variables panel in the interface editor.
Thank you so much, Stefan and Mike! I did some tweaks on the code for the fv!item and it works