Transform the Invoice to customer payment.

      let customerPayment = record.transform({
          fromType: record.Type.INVOICE,
          fromId: invoiceId,
          toType: record.Type.CUSTOMER_PAYMENT,
          isDynamic: true,
        });
       
let acc = customerPayment.setValue({
          fieldId: 'account',
          value: paymentAccount
          
})
       
let lineCount = customerPayment.getLineCount({
          sublistId: 'apply'

          })
        
for (let i = 0; i < lineCount; i++) {
          let isApplied = customerPayment.getSublistValue({
            sublistId: 'apply',
            fieldId: 'apply',
            line: i
          });
          
let refnum = customerPayment.getSublistValue({
            sublistId: 'apply',
            fieldId: 'refnum',
            line: i
          })
          
if (refnum == invoiceRefNo && isApplied) {
           let paymentAmt = customerPayment.setCurrentSublistValue({
              sublistId: 'apply',
              fieldId: 'amount',
              line: i,
              value: paymentAmount

            });
            customerPayment.commitLine({
              sublistId: 'apply'
            });
          }
         }

       let cpId = customerPayment.save({
          enableSourcing: true,
          ignoreMandatoryField: true
        });
        

Leave a comment

Your email address will not be published. Required fields are marked *