0

I have GenericValue called value that I use to put transaction details before proceeding to the delegator.create(makevalue) inside try-catch block

I want to check the amount inside the delegator before that try-catch block if it's really a BigDecimal or a String was put inside and return the error to the client before I get that database error.

How can I get that amount field inside that makevalue GenericValue?

public static Map<String, Object> createTransaction(Delegator delegator, String caseIds, BigDecimal amountToPay,String createdBy) {
        
        String caseId = caseIds.replaceAll(",", "");
        GenericValue caseELI = getEntityValue(delegator,"Cases", "caseId", caseId);
        GenericValue makeValue = delegator.makeValue("AccountTransaction");
            Long accountTransactionId = delegator.getNextSeqIdLong("AccountTransaction");
            
            makeValue.put("accountTransactionId", accountTransactionId);
            makeValue.put("caseId",caseId);
            makeValue.put("clientId", caseELI.getString("clientId"));
            makeValue.put("amount",amountToPay);
            makeValue.put("isCash","Y");
            makeValue.put("isPosted","Y");
            makeValue.put("createdBy",createdBy);

            


            try {
                delegator.create(makeValue);
            } catch(GenericEntityException e){
                e.printStackTrace();
            }

          Map<String, Object> result = ServiceUtil.returnSuccess("Transaction processed successfully");
          return result;
    }
MAXWEL OCHIENG
  • 170
  • 1
  • 14
  • Hi Maxwel, I'm not sure to understand. "amountToPay" must be a BigDecimal passed to createTransaction(). So you want to check amountToPay upstream of a call to createTransaction() to see if not a string would be passed there, right? – JacquesLeRoux Sep 29 '22 at 13:53
  • yes @JacquesLeRoux that is my question. – MAXWEL OCHIENG Oct 02 '22 at 17:56

1 Answers1

0

It depends of what is your call stack at the moment. I guess you use a service to call createTransaction. Then you can check that in the service. Else we need to know what is the call stack at the moment.

HTH

JacquesLeRoux
  • 577
  • 4
  • 10