3
votes

I was able to make the api work in php and search customer by internal id. However i have a scenario, where i'll be searching a customer by a custom field. Under Customer and it has a custom tab contains multiple domain name and domain details.

For example :

Main search criteria : Domain Name

How is this possible in netsuite php api? Much appreciated for any help. im only newbie to NetSuite. How will i modify this sample code to search by custom field?

$service = new NetSuiteService();
$request = new GetRequest();
$request->baseRef = new RecordRef();
$request->baseRef->internalId = "1780";
$request->baseRef->type = "customer";
$getResponse = $service->get($request);

if (!$getResponse->readResponse->status->isSuccess) {
    echo "GET ERROR";
} else {
    $customer = $getResponse->readResponse->record;
    //var_dump($customer);
    echo "GET SUCCESS, customer:";
    echo "\nCompany name: ". $customer->companyName;
    echo "\nInternal Id: ". $customer->internalId;
    echo "\nEmail: ". $customer->email;
    echo "\nCustomerID: ". $customer->firstName;
}

OK, I'm trying to get the custom record of all domains base from egrubaugh360.

$service = new NetSuiteService();
$request = new GetRequest();

$request->baseRef = new CustomRecordRef();
$request->baseRef->internalId = "47";
//$request->baseRef->externalId = "xxxx";
$request->baseRef->typeId = "custom_list_domains";

$getResponse = $service->get($request);

var_dump($getResponse);

if (!$getResponse->readResponse->status->isSuccess) {
    echo "GET ERROR";
} else {
    var_dump($getResponse->readResponse->record);
    echo "GET SUCCESS";
}

I'm not sure what to put in "typeId", what exactly is the type to put? It gives me error "Invalid custom record type key"

object(GetResponse)#8 (1) { ["readResponse"]=> object(ReadResponse)#9 (2) { ["status"]=> object(Status)#10 (2) { ["statusDetail"]=> array(1) { [0]=> object(StatusDetail)#11 (3) { ["code"]=> string(26) "INVALID_CSTM_RCRD_TYPE_KEY" ["message"]=> string(31) "Invalid custom record type key." ["type"]=> string(5) "ERROR" } } ["isSuccess"]=> bool(false) } ["record"]=> NULL } }
3

3 Answers

3
votes

Here is a general example of searching for a customer by a custom field.

You can modify to fit your need.

$NSservice = new NetSuiteService();
$NSservice->setSearchPreferences(false, 10);

$cs = new CustomerSearch();
$csb = new CustomerSearchBasic();

$domain = new SearchCustomStringField();
$domain->internalId = 'yourcustomfieldinternalid';
$domain->searchValue = 'text you are searching for';
$domain->operator = 'is';

$scfl = new SearchCustomFieldList();
$scfl->customField = array($domain);
$csb->customFieldList = $scfl;
$cs->basic = $csb;

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

$searchResponse = $NSservice->search($request);
1
votes

Instead of doing a GetRequest, you will want to do a SearchRequest. Your $request should become a CustomerSearchBasic object. You can then use $request->customFieldList to add a list of SearchCustom*Field filters. Build a new SearchCustomStringField, for instance, if the custom field you're filtering on is a text field. Then you will use $service->search($request); to execute the search. See here for the full PHP Toolkit docs.

It sounds like your domain names may actually be a custom sublist, not just a custom field. If this is the case, you will want to be doing a search of the custom Domain record instead of the Customer record. Then you can look for all Domains where the Customer is 1780, along with any other filters you might want.

1
votes

As per previews ans code customer Search by custom field just 1 issue below line.

$domain = new SearchCustomStringField();

replace:

$domain = new SearchStringCustomField();