``` var payment = record.load({ ...
# suitescript
s
Copy code
var payment = record.load({
                    type: record.Type.CUSTOMER_PAYMENT,
                    id: srch.id,
                    isDynamic: true
                });
                var unappliedAmount = payment.getValue('unapplied');
                if (unappliedAmount > 0){
                    payment.selectNewLine({
                        sublistId: "apply"
                    });

                    payment.setCurrentSublistValue({
                        sublistId: 'apply',
                        fieldId: 'apply',
                        value: true
                    });
                    payment.setCurrentSublistValue({
                        sublistId: 'apply',
                        fieldId: 'payment',
                        value: unappliedAmount
                    });
                    payment.setCurrentSublistValue({
                        sublistId: 'apply',
                        fieldId: 'internalid',
                        value: openInvoices[i].id
                    });
                    payment.commitLine({
                        sublistId: 'item'
                    });
                    var saveRet = payment.save({
                        enableSourcing: false,
                        ignoreMandatoryFields: true
                    });
                    log.debug("saveRet", saveRet);
                }
I have a payment record loaded, there is an unapplied amount and I want to apply it to an open invoice. Is this not the way to go about it?
s
I think you'll want to select the apply line, not create it
👍 1