Netsuite SuiteTalk - requesting a list of invoices for a client through PHP

I am using the Netsuite PHP Toolkit to try and get a list of invoices for a client. I can make a call (using TransactionSearch) without problems, but I'm struggling to figure out how I should get all the data for the invoice, i.e. information about the invoice header (e.g. total amount, currency, main menu bar and etc.), as well as data for each position (net value, taxable value, clause, etc.).

I tried several approaches:

  • TransactionSearchAdvanced, with the specified return columns and returnSearchColumns set to false. This returns all individual lines (woo!), But things like currency and term don't expand - you just get internalId, not the actual text (or character). Also, with TSA, do you really need to specify each column that you want? that is, by default is really just an empty set of fields? Is there no way to say "give me all the details for all the lines of each invoice?"

  • TransactionSearch, with the preference returnSearchColumns set to true. This gives a list of single records of the type of invoice, while the entire currency and term are correctly filled, but, unfortunately, not a single line item. It is rather a summary.

So, I was left with several options, none of which are very pleasant, namely:

  • Calling and for all invoices and combining data. These searches take a lot of time (performance is another bug for me, so I really don't want to do this.

or

  1. Define a method for requesting data for conditions, currencies, etc., as well as a method for obtaining invoices.

I have no idea how you should do this, and cannot find anything on the Internet about this. This is one of the worst interfaces I've used (and I used some pretty bad ones).

Any help would be greatly appreciated.

+4
source share
4 answers

, - API - (aka SuiteTalk). , , , . , , .

Faz, REST , -.

:

  • , , ( , )
  • RESTet Javascript, ,
  • RESTlet .

I: , . , , . .

II: RESTlet , . NetSuite. IDE NetSuite, , . .

, , , . - - , , :

function getSearchResults(){
var max_rows = 1000;
var search_id = 1211;
var search = nlapiLoadSearch(null, search_id);
var results = search.runSearch();
var rows = [];

// add starting point for usage
var context = nlapiGetContext();
startingUsage = context.getRemainingUsage();
rows.push(["beginning usage", startingUsage]);

// now create the collection of result rows in 1000 row chunks
var index = 0;
do{
    var chunk = results.getResults(index, index+1000);
    if( ! chunk ) break;
    chunk.forEach( function(row){
        rows.push(row);
        index++;
    });
}while( chunk.length === max_rows);

// add a line that returns the remaining usage for this RESTlet
context = nlapiGetContext();
var remainingUsage = context.getRemainingUsage();
rows.push(["remaining usage",remainingUsage]);

// send back the rows
return rows;
}

, :

var search = nlapiLoadSearch(null, SEARCH_ID);
var resultSet = search.runSearch();

getResults(), 1000 , NetSuite. script NetSuite . - , . GET getSearchResults. , , , . , , IDE = D. " REST".

III. , , REST , . Python, . Python:

import requests
import json
url = 'https://rest.sandbox.netsuite.com/app/site/hosting/restlet.nl?script=123&deploy=1'
headers = {'Content-Type': 'application/json', 'Authorization':'NLAuth nlauth_account=1234567, nlauth_email=someone@somewhere.com, nlauth_signature=somepassword, nlauth_role=3'}
resp = requests.get(url, headers=headers)
data = resp.json()

URL- RESTlet. , , , .

,

  • NetSuite
  • SuiteScript
  • REST .

, .

+2

Netsuite restlet. , , .

Restlet , -.

+1

script

script

function customSearch(request, response) {
	var rows = [];	
	var result;
	var filters = [];
	//9989 is customer internal id you can add more
	// by pushing additional ids to array
    filters.push(new nlobjSearchFilter('entity', null, 'anyOf', [9989] ));
	var invoiceList = nlapiSearchRecord('invoice', null, filters, []);
	// by default record limit is 1000 
	// taking 100 records 
  for (var i = 0; i < Math.min(100, invoiceList.length); i++)
    {
        if (parseInt(invoiceList[i].getId()) > 0) {
            recordid = invoiceList[i].getId();
            try {
               result=  nlapiLoadRecord(invoiceList[i].getRecordType(), recordid);   
			   // pushing in to result
			   rows.push(result);			
            } catch (e) {
                if (e instanceof nlobjError) {
                    nlapiLogExecution('DEBUG', 'system error', e.getCode() + '\n' + e.getDetails());
                } else {
                    nlapiLogExecution('DEBUG', 'unexpected error', e.toString());
                }
            }
        } 
    }
	response.setContentType('JSON');
	response.write(JSON.stringify({'records' : rows}));
	return;

}
Hide result
    } 
}
response.setContentType('JSON');
response.write(JSON.stringify({'records' : rows}));
return;

}

0

- :

    public function getCustomerInvoices($customer_id)
{

    $service = new NetSuiteService($this->config);
    $customerSearchBasic = new CustomerSearchBasic();
    $searchValue = new RecordRef();
    $searchValue->type = 'customer';
    $searchValue->internalId = $customer_id;
    $searchMultiSelectField = new SearchMultiSelectField();
    setFields($searchMultiSelectField, array('operator' => 'anyOf', 'searchValue' => $searchValue));
    $customerSearchBasic->internalId = $searchMultiSelectField;

    $transactionSearchBasic = new TransactionSearchBasic();
    $searchMultiSelectEnumField = new SearchEnumMultiSelectField();
    setFields($searchMultiSelectEnumField, array('operator' => 'anyOf', 'searchValue' => "_invoice"));

    $transactionSearchBasic->type = $searchMultiSelectEnumField;

    $transactionSearch = new TransactionSearch();
    $transactionSearch->basic = $transactionSearchBasic;
    $transactionSearch->customerJoin = $customerSearchBasic;

    $request = new SearchRequest();
    $request->searchRecord = $transactionSearch;

    $searchResponse = $service->search($request);

    return $searchResponse->searchResult->recordList;

}
0

All Articles