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.

Beginner Asked on December 5, 2023 in Other.
Add Comment
5 Answer(s)

Thanks for your response. Will test them and then update you regarding that

Beginner Answered on December 5, 2023.
Add Comment

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}'
Beginner Answered on December 5, 2023.
Add Comment

. 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:

PHP
// 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();
Beginner Answered on December 5, 2023.
Add Comment

3. Sample Code for Multiple Linked Record Types:

Here’s an example combining searches for invoices, cash sales, and RMAs:

PHP
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);
Beginner Answered on December 5, 2023.
Add Comment

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!

Beginner Answered on December 5, 2023.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.
  • This site made possible by our sponsors:   Tipalti   Celigo   Become a Sponsor   Become a Sponsor