Published on November 04, 2024.
This SuiteQL query returns the invoices to which a customer payment was applied. The corresponding sales order number is returned, along with the customer's PO number, and the amount applied.
SELECT Invoice.TranID AS InvoiceID, REPLACE( BUILTIN.DF( InvoiceMainLine.CreatedFrom ), 'Sales Order #', '' ) AS SONumber, Invoice.OtherRefNum AS CustomerPO, PTLL.ForeignAmount AS AmountPaid FROM Transaction AS Payment INNER JOIN TransactionLine AS PaymentLine ON ( PaymentLine.Transaction = Payment.ID ) AND ( PaymentLine.MainLine = 'F' ) INNER JOIN PreviousTransactionLineLink AS PTLL ON ( PTLL.NextDoc = PaymentLine.Transaction ) AND ( PTLL.NextLine = PaymentLine.ID ) AND ( PTLL.LinkType = 'Payment' ) INNER JOIN TransactionLine AS InvoiceLine ON ( InvoiceLine.Transaction = PTLL.PreviousDoc ) AND ( InvoiceLine.ID = PTLL.PreviousLine ) INNER JOIN Transaction AS Invoice ON ( Invoice.ID = InvoiceLine.Transaction ) INNER JOIN TransactionLine AS InvoiceMainLine ON ( InvoiceMainLine.Transaction = Invoice.ID ) AND ( InvoiceMainLine.MainLine = 'T' ) WHERE ( Payment.ID = 7518243 )
Hello, I'm Tim Dietrich. I develop custom software for businesses that are running on NetSuite, including mobile apps, Web portals, Web APIs, and more.
I'm the developer of several popular NetSuite open source solutions, including the SuiteQL Query Tool, SuiteAPI, and more.
I founded SuiteStep, a NetSuite development studio, to provide custom software and AI solutions - and continue pushing the boundaries of what's possible on the NetSuite platform.
Copyright © 2025 Tim Dietrich.