NetSuite API Search Front End

I am trying to find a NetSuite Vendor (which may or may not exist in NetSuite) using the NetSuite API; however, the only part of the information that I have about the Seller is external. My goal is to request NetSuite for the Provider with the given external identifier, and if the provider exists, use it in a subsequent API call. If the provider does not exist, I will create it and use only the one that I just created in a subsequent API call.
Despite my searches, I could not find a way to search NetSuite for recording via externalId (I found many ways to search by field, but I did not find a way to search by attribute ie externalId). Any help is appreciated.

+4
source share
4 answers

After further research and a little help, I figured out how to search by externalId. Hope this will be useful for someone in the future:

Using php: Create a new GetRequest () object and a new RecordRef () object; set the RecordRef externalId parameter to the required external identifier; set the RecordRef type to "vendor"; set the GetRequest baseRef to the RecordRef that you just created using the NetSuite client, execute the get ( ) passing the GetRequest () object created earlier. The get () method returns GetResponse () containing information about your search (and the object, if one exists).

$getRequest = new \NetSuite\WebServices\GetRequest();
$recordRef = new \NetSuite\WebServices\RecordRef();
$recordRef->externalId = "theExternalIdGoesHere";
$recordRef->type = "vendor";
$getRequest->baseRef = $recordRef;
$response = $client->get($getRequest);
+5
source

Using Restlet

var vendorFilter = [];
vendorFilter.push(new nlobjSearchFilter('externalid',null,'is',dataIn.externalid);


var vendorList = nlapiSearchRecord('vendor',null,vendorFilter,null);

var record = (vendorList!=null) ? nlapiLoadRecord('vendor',vendorList[0].getId()) : nlapiCreateRecord('vendor');

// process your logic
+3
source

user5227543 , , vendorList.length > 0 :

var record = (vendorList! = null & vendorList.length> 0)? nlapiLoadRecord ('vendor', vendorList [0] .getId ()): nlapiCreateRecord ('vendor');

0
source

Here is a snippet for C #: (I used an externalId array, just in case you need more than one)

1. Creating a search in a multisect field

SearchMultiSelectField field =
new SearchMultiSelectField
{
    @operator = SearchMultiSelectFieldOperator.anyOf,
    operatorSpecified = true
};

var itemList = new List<com.netsuite.webservices.RecordRef>();
foreach (var externalId in externalIds)
{
    var recRef = new com.netsuite.webservices.RecordRef
    {
        externalId = externalId
    };
    itemList.Add(recRef);
}           

field.searchValue = itemList.ToArray();

var basic = new TransactionSearchBasic {externalId = field};

2. Call search function during maintenance:

NetSuiteService service; // Instantiate with netsuite creds
SearchResult results = service.search(selectSearch);

List<Record> transactions = new List<Record>();

if (results?.status?.isSuccess ?? false)
{
    for (int i = 1; i <= results.totalPages; i++)
    {
        var recordList = results.recordList;
        transactions.AddRange(recordList);
    }
}
else if (results?.status != null)
{
    this.log.Debug(GetStatusDetails(results.status));
}
else
{
    this.log.Debug("Failed to recieve results");
}

return transactions;
0
source

Source: https://habr.com/ru/post/1544007/


All Articles