Im creating a customer payment on invoice save in ...
# suitescript
n
Im creating a customer payment on invoice save in afterSubmit (if status is approved). However, for some reason it is setting it as Undeposited funds account instead of the actual account.
Copy code
var custPayRec = record.create({
                    type: 'customerpayment',
                    isDynamic: true
                });

                custPayRec.setValue({
                    fieldId: 'customer',
                    value: customer,
                });

                //custPayRec.setValue({fieldId : 'account', value : 1});
                custPayRec.setValue({fieldId : 'autoapply', value : false});
                

                var lineCount = custPayRec.getLineCount({sublistId: 'apply'});

                for (var i = 0; i < lineCount; i++) {
                    var invoiceLineId = custPayRec.getSublistValue({ sublistId: 'apply', fieldId: 'internalid', line: i}) * 1;
                    var invoiceLineAlt = custPayRec.getSublistValue({ sublistId: 'apply', fieldId: 'doc', line: i}) * 1;
                    var total = custPayRec.getSublistValue({ sublistId: 'apply', fieldId: 'total', line: i});

                    if (invoiceLineId == invoiceId * 1 || invoiceLineAlt == invoiceId * 1) {
                        custPayRec.selectLine({
                            sublistId: 'apply',
                            line: i
                        });
                        custPayRec.setCurrentSublistValue({
                            sublistId: 'apply',
                            fieldId: 'apply',
                            value: true
                        });
                        custPayRec.commitLine({
                            sublistId: 'apply'
                        });
                    }
                }

                custPayRec.setValue({fieldId : 'payment', value : total});
                custPayRec.setValue({fieldId : 'creditcard', value : defaultCC});

                customerPayment = custPayRec.save();
c
When you say on invoice save, does the invoice exist yet? What entry point are you using?
n
it already exists and it is on aftersubmit
b
which account does the payment method deposit to?
n
If you do a customer payment in UI it defaults to 1000 Checking but when I use SuiteScript i get this
@battk
e
if it's a cc payment, set the
ccapproved
field to true
n
@ehcanadian still same issue
b
what does the payment event say?
n
Payment event?
b
the payment event would be on the payment
n
message has been deleted
b
there are 7 subtabs on your payment
go search through them until you find the one with the payment event
n
Hm not seeing a payment event tab
b
it should be a secondary subtab under one of the 7 primary ones
if its not there, your form sucks and you want to use the standard payment form
n
Switched to standard for and found it. "No records to show"
b
that sounds weird, you dont usually get to an unapproved payment without your payment processor rejecting the credit card
n
@battk figured it out. I had to in my script set this:
Copy code
custPayRec.setValue({fieldId : 'handlingmode', value: 'PROCESS'});
it was defaulting to SAVE_ONLY