I am getting error when creating customer refund ,...
# suitescript
n
I am getting error when creating customer refund , any one can check and tell me what wrong in my code. Error: "type": "error.SuiteScriptError", "name": "SSS_INVALID_SUBLIST_OPERATION", "message": "You have attempted an invalid sublist or line item operation. You are either trying to access a field on a non-existent line or you are trying to add or remove lines from a static sublist.",
Copy code
var createCustomerRefund = record.create({
                type: record.Type.CUSTOMER_REFUND,
                isDynamic: false,
                defaultValues: { entity: creditMemoId.getValue("entity") }
            });
            createCustomerRefund.setValue({
                fieldId: 'entity',
                value: creditMemoId.getValue("entity")
            });
            createCustomerRefund.setValue({
                fieldId: 'customer',
                value: "34959"
            });
            //var paymentmethodData = paymentmethod.getPaymentMethods({ "partyId":partyId });
            createCustomerRefund.setValue({
                fieldId: 'paymentmethod',
                value: 11
            });
            var configurations = config.load({
                type: "companypreferences"
            });
            var accountId = configurations.getValue("custscriptaccountid");
            createCustomerRefund.setValue({
                fieldId: 'account',
                value: accountId
            });
            var numLines = createCustomerRefund.getLineCount({
                sublistId: 'apply'
            });
            log.debug("numLines:::::", numLines);
            for (var i = 0 ; numLines > i; i++) {
                var id = createCustomerRefund.getSublistValue({ sublistId: 'apply', fieldId: 'doc', line: i })
                if(id == creditMemoId.id){
                createCustomerRefund.setSublistValue({
                    sublistId: 'apply',
                    fieldId: 'apply',
                    value: true,
                    line: i
                });

                log.debug(
                    i + 'line:::::: ' +
                    createCustomerRefund.getSublistValue({ sublistId: 'apply', fieldId: 'doc', line: i }) + ' ' +
                    createCustomerRefund.getSublistValue({ sublistId: 'apply', fieldId: 'apply', line: i }) + ' ' +
                    createCustomerRefund.getSublistValue({ sublistId: 'apply', fieldId: 'amount', line: i }) + ' ' +
                    createCustomerRefund.getSublistValue({ sublistId: 'apply', fieldId: 'total', line: i }))
                }
                
            }
            return createCustomerRefund.save();
b
i would guess its all the attempts to set the entity/customer field
try removing
Copy code
createCustomerRefund.setValue({
                fieldId: 'entity',
                value: creditMemoId.getValue("entity")
            });
            createCustomerRefund.setValue({
                fieldId: 'customer',
                value: "34959"
            });
you should also be able to automatically select the appropriate credit memo by using the cred default value
Copy code
var createCustomerRefund = record.create({
  type: record.Type.CUSTOMER_REFUND,
  isDynamic: false,
  defaultValues: {
    entity: creditMemoId.getValue("entity"),
    cred: creditMemoId.id
  }
});
n
@battk Thank you! . Its worked.