How to save both a!save as only one a!save is working for IF condition in allocation type = 5

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

Parents
  • 0
    Certified Lead Developer

    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.

Reply
  • 0
    Certified Lead Developer

    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.

Children