Netsuite get records using Sales Order Internal ID
I am using the PHP Toolkit to retrieve Netsuite Sales Order details using pre-built search techniques. I have the internal ID of a sales order, and I want to retrieve records linked to that sales order, such as invoices, cash sales, RMAs, etc. If you have any insights on this or sample code, please update or share it.
Thanks for your response. Will test them and then update you regarding that
I’m happy to help! Here’s how you can use the PHP Toolkit to retrieve linked records from a NetSuite sales order:
1. Identifying Linked Record Types:
First, determine the specific types of linked records you’re interested in (invoices, cash sales, RMAs, etc.). Each record type has its own internal ID and search criteria. Here are some common examples:
- Invoice: RecordType::INVOICE, search criteria:
internalid = '<span class="math-inline">\{salesOrderId\}'\* **Cash Sale:** RecordType::CASH_SALE, search criteria: `createdfrom.internalid = ‘{salesOrderId}’` - RMA: RecordType::RETURN_AUTHORIZATION, search criteria:
salesorder.internalid = '${salesOrderId}'
. Using Pre-built Search Techniques:
The PHP Toolkit offers pre-built search techniques for various record types. You can leverage them to efficiently retrieve linked records:
// Use the Record::get() method for single record retrieval
$invoice = Record::get(RecordType::INVOICE, $invoiceId);
// Use the Search::create() method for multi-record searches
$cashSalesSearch = Search::create(RecordType::CASH_SALE);
$cashSalesSearch->addColumn('internalid'); // Select only internal IDs
$cashSalesSearch->addFilter('createdfrom.internalid', $salesOrderId);
$cashSales = $cashSalesSearch->run();
// Use custom filters and columns for RMAs
$rmaSearch = Search::create(RecordType::RETURN_AUTHORIZATION);
$rmaSearch->addColumn('tranid', 'tran_id'); // Rename returned column
$rmaSearch->addFilter('salesorder.internalid', $salesOrderId);
$rmas = $rmaSearch->run();
3. Sample Code for Multiple Linked Record Types:
Here’s an example combining searches for invoices, cash sales, and RMAs:
function getLinkedRecords($salesOrderId) {
$linkedRecords = [];
// Invoice
$invoice = Record::get(RecordType::INVOICE, $salesOrderId);
if ($invoice) {
$linkedRecords['invoice'] = $invoice;
}
// Cash Sales
$cashSalesSearch = Search::create(RecordType::CASH_SALE);
$cashSalesSearch->addColumn('internalid');
$cashSalesSearch->addFilter('createdfrom.internalid', $salesOrderId);
$cashSales = $cashSalesSearch->run();
if ($cashSales->count() > 0) {
$linkedRecords['cash_sales'] = $cashSales->getRecords();
}
// RMAs
$rmaSearch = Search::create(RecordType::RETURN_AUTHORIZATION);
$rmaSearch->addColumn('tranid', 'tran_id');
$rmaSearch->addFilter('salesorder.internalid', $salesOrderId);
$rmas = $rmaSearch->run();
if ($rmas->count() > 0) {
$linkedRecords['rmas'] = $rmas->getRecords();
}
return $linkedRecords;
}
// Usage example
$salesOrderId = 1234;
$linkedRecords = getLinkedRecords($salesOrderId);
print_r($linkedRecords);
- You can modify the searches to include additional columns you need from each record type.
- Consider using the
RecordRefclass to easily reference linked records within your code. - Explore the PHP Toolkit documentation for detailed information on searches and record manipulation: https://docs.oracle.com/en/cloud/saas/netsuite/ns-online-help/section_N3534011.html
I hope this gives you a good starting point for retrieving linked records from NetSuite sales orders using the PHP Toolkit. Feel free to ask if you have any further questions or need specific code examples for different linked record types!



