Check value in field before proceeding to delagator.create()

23 views Asked by At

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;
    }
1

There are 1 answers

0
JacquesLeRoux On

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