I can't figure out what's going wrong here. I can ...
# suitescript
d
I can't figure out what's going wrong here. I can create a standalone credit memo fine. But if I try to create the credit memo and apply it to an invoice, it fails.
Copy code
creditMemoRecord.setValue('autoapply', false);
        let payAmount = Number(creditMemoRecord.getValue('amountremaining'));
        
        for (let lineIndex = 0; lineIndex <= creditMemoRecord.getLineCount('apply'); lineIndex++){
        
            if (invoiceId == creditMemoRecord.getSublistValue('apply', 'doc', lineIndex)) {
                didApply = true;
                                             
                creditMemoRecord.selectLine({ sublistId: 'apply', line:lineIndex });                
                                
                creditMemoRecord.setCurrentSublistValue({ sublistId: 'apply', fieldId: 'apply', value: true });
                creditMemoRecord.setCurrentSublistValue({ sublistId: 'apply', fieldId: 'amount', value: payAmount });                                
            }           
        }
I get the following error:
Copy code
{
  "error": {
    "code": "SSS_INVALID_SUBLIST_OPERATION",
    "message": "{\"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.\",\"stack\":[\"Error\"],\"cause\":{\"type\":\"internal error\",\"code\":\"SSS_INVALID_SUBLIST_OPERATION\",\"details\":\"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.\",\"userEvent\":null,\"stackTrace\":[\"Error\"],\"notifyOff\":false},\"id\":\"\",\"notifyOff\":false,\"userFacing\":true}"
  }
}
Does anyone have any idea why this would be failing? There's no issue via the UI doing this.
b
<=
: causes the error at the last iteration of your loop
d
yes, that could well be it! a stupid oversight translating 1 based index starts from SS1 code into SS2
I'll try it out now, great catch
Yup - that works, well, it advances my error onto something else but I think I can fix that. Thanks @battk