I'm trying to create a payment from an invoice whe...
# ask-stanley-ai
l
I'm trying to create a payment from an invoice where credits balance out the payment amount to 0, so that NetSuite doesn't actually create the customer payment, but apply the chosen crediting transactions to the invoice thru suitescript, if I do it thru the UI and log the record in an aftersubmit, I can see that the "payment" field is 0, but if I try to set it to 0 in the suitescript I get "Value 0.0 outside of valid min/max range for field payment" how can I solve this? what other fields are important so that a new payment is not created but rather the apply the chosen crediting transactions to the invoice?
c
AI generated answer (using internal Slack threads):
Based on the conversations, it seems that you are trying to apply credits to an invoice without creating a customer payment record. However, in NetSuite, you need to create a customer payment to properly record the application of credits. Here's a general approach to achieve this: 1. Use
record.transform
to mimic the effect of the
Accept Payment
button in the UI. This will transform the invoice into a customer payment record.
Copy code
javascript
var paymentRecord = record.transform({
    fromType: record.Type.INVOICE,
    fromId: invoiceId,
    toType: record.Type.CUSTOMER_PAYMENT,
    isDynamic: true,
});
2. Use
Record.findSublistLineWithValue
or
Record.getSublistValue
to find the line you want to mark. This will usually involve finding the line with the credit memo or journal entry you want to apply.
Copy code
javascript
var creditLineNumber = paymentRecord.findSublistLineWithValue({
    sublistId: 'credit',
    fieldId: 'internalid',
    value: newJourId
});
3. Use
Record.setSublistValue
to mark the same checkboxes you would in the UI. This will apply the credit to the invoice.
Copy code
javascript
paymentRecord.setSublistValue({
    sublistId: 'credit',
    fieldId: 'apply',
    line: creditLineNumber,
    value: true
});
4. Save the record. If the credits balance out the payment amount to 0, NetSuite might not actually create the customer payment, but it will apply the chosen crediting transactions to your invoice.
Copy code
javascript
var paymentRecordId = paymentRecord.save({
    enableSourcing: true,
    ignoreMandatoryFields: true
});
Remember to set
isDynamic
to
true
when transforming the record. This allows you to work with the record in a more interactive way, similar to how a user would in the UI. ****** Disclaimer: This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes. ******
Slack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.85905838
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.858177483
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.854147911
Please provide your feedback on this answer.