Netsuite PHP ToolKit Tips and Code Samples


I have been working on Netsuite PHP Toolkit for some time. Below are some code samples and tips I found useful. Any suggestion/comments are welcome.

Tips

Netsuite Webservices have concurrent session issue. This can be handled by adding a simple loop in make call function.

In PHPToolkit functions are not enclosed in try catch blocks. It is a good practice to add them to be safe from unexpected results.

GetAll Operation can be used to fetch many type of lists in netsuite

$result = $myNSClient->getAll(‘supportCaseIssue’);

Get Operation

$RecordRef = new nsRecordRef(array('internalId' => 23, 'type' => 'customer'));
$getResponse = $myNSClient->get($RecordRef);

Search by Internal Id

$search = new nsComplexObject("ContactSearchBasic");
$search->setFields(array("internalId" => array("operator" => 'anyOf', "searchValue" => new nsRecordRef(array('internalId' => ‘24’, 'type' => 'contact')))));
$searchResponse = $myNSClient->search($search);

Clearing Fields
In update operation if you want to clear an already set field you have to use nullfield list.
Below is the code to clear the email and phone fields in any case object.

$nullFieldArray = array();
$nullFieldArray['name'] = array();
$nullFieldArray['name'][] = ‘email’;
$nullFieldArray['name'][] = ‘phone’;
$caseFields['nullFieldList'] = $nullFieldArray;

Join Search

Get companies attached with a contact

$searchAdvance = new nsComplexObject('CustomerSearchAdvanced');
$search = new nsComplexObject('CustomerSearch');

$searchBasic = new nsComplexObject('ContactSearchBasic');
$searchMultiSelectField = new nsComplexObject('SearchMultiSelectField');
$searchValue = new nsRecordRef(array('type' => 'contact', 'internalId' => $contactInternalId));
$searchMultiSelectField->setFields( array( 'operator'=>'anyOf','searchValue'=>$searchValue));
$searchBasic->setFields(array('internalId'=>$searchMultiSelectField));
$joinFields = array('contactJoin'=>$searchBasic);
$search->setFields($joinFields);
$searchAdvance->setFields(array('criteria'=>$search));
$searchResponse = $myNSClient->search($searchAdvance);

Edit: Netsuite PHP Toolkit has gone through a major change in version 2012_2. So people using PHP Toolkit 2012_2 or later should change the code accordingly.

You can download the old API from here.

Advertisements

I am a web developer working @ Gaditek

Tagged with: , , ,
Posted in Netsuite, Programming & Development
72 comments on “Netsuite PHP ToolKit Tips and Code Samples
  1. […] Webservices have concurrent session issue. This can be handled by adding a simple loop in… [full post] dreamxtream DreamXtream's Blog netsuiteprogramming & developmentbest practicesprogramming […]

  2. Neil Hastings says:

    Thanks for posting this. I’m trying to figure out where to get the valid types for ->getAll(). Where did you get the valid list?

  3. dreamxtream says:

    WebService Supported Records ( https://system.netsuite.com/help/helpcenter/en_US/Output/Help/SuiteFlex/WebServices/STR_SupportedRecords.html ) contains documentation for all record. You can get the detail of every record type and see if it support getAll operation or not.

  4. Neil Hastings says:

    Thank you. That’s what has been missing for me.

  5. Anonymous says:

    Maki: I writing .Net application using Netsuite WSDL. I need to search for Support Case. I was able to get that, but not the messages associated with a case. I see that there is messagesjoin functionality, but I am not sure how to use it. Does anyone have idea how to do that. Thank you.

  6. stagg says:

    I haven’t written any real code in about 10 years now. I am very rusty at writing, but still read many programming languages fluently. I’m finding that the netsuite documentation on their PHP api is really less than stellar at this point. Anyways, for right now I have the php samples, I can add a customer. What I’m wanting do find is the response to the myNSclient->add($customer).

    Basically, i’m wanting build a customer portal that accesses bits and pieces of information from several different systems and assembles it nicely in a web UI where the end user has some limited actions that they can perform. The ability to add, and update customer data in netsuite (more generically ERP) is a cornerstone in this development effort. Since the ERP data is cornerstone, I want to use the ERP customer ID’s as keys in my own local system.

    Any insight is appreciated, I’ll keep googling, and working with the examples in the meantime.

  7. dreamxtream says:

    @stagg
    Here is the code to get the customer id
    $addResponse = $myNSClient->add($customer);
    if ($addResponse->isSuccess)
    $id = $addResponse->recordRef->nsComplexObject_fields[‘internalId’];

  8. shelly warren says:

    I love your post!!! Thank you!!!
    I have been trying to teach myself how to integrate with netsuite, seems like I must be missing something… The goal is to return a set of customer records with an entity status condition, for instance give me all customers with a ‘closed’ status, below are the two ways I have attempted this but I must be missing something, any help would be terrific!

    Try 1
    $RecordRef = new nsRecordRef(array(‘entitystatus’ => 17, ‘type’ => ‘customer’));
    $searchResponse = $myNSclient->get($RecordRef);

    Try 2
    $itemIdSearchField = new nsComplexObject(“SearchMultiSelectField”);
    $itemIdSearchField->setFields(array(“searchValue” => new nsListOrRecordRef(array(‘internalId’ => $itemId)),”operator” => “anyOf”));
    $itemSearch = new nsComplexObject(“CustomerSearch”);
    $itemSearch->setFields(array(“entitystatus” => $itemIdSearchField));
    $searchResponse = $myNSclient->search($itemSearch);

    Thank you for any suggestions…

  9. dreamxtream says:

    @shelly warren
    hope code below is what you want

    $customerSearch = new nsComplexObject(“CustomerSearchBasic”);
    $customerSearchFields[‘entityStatus’] = array(“operator” => “anyOf”,
    “searchValue” => array(new nsRecordRef(array(‘type’ => ‘customerStatus’,
    ‘internalId’ => 17))));
    $customerSearch->setFields($customerSearchFields);
    $myNSClient->search($customerSearch);

  10. stagg says:

    Would you happen to have a cashsale sample that you could share?

    Below is my little r&d sample script that I’ve been trying to record a cashsale with.

    /* statically setting some post variables while I learn how to do this */
    $entity = 1376; // post variable
    $itemIntId = 136; // post variable 136 is a misc item.
    $quantity = 1; // post variable
    $price = 10.00; // post variable, a custom value for the misc item
    $email = ‘ima@user.com’; // maybe post variable, maybe obtained by some other means
    $paymentmethod = 1; // 1 is for cash method. setup->accounting->accounting lists

    global $myNSclient;
    global $account;

    $cashSaleFields = array(

    ‘entity’ => new nsRecordRef(array(‘internalId’ => $entity)),
    ‘paymentmethod’ => $paymentmethod,
    ‘chargeit’ => false,
    ‘undepfunds’ => true,

    ‘itemList’ => array(
    ‘item’ => array(
    ‘item’ => array(‘internalId’ => $itemIntId),
    ‘quantity’ => $quantity,
    ‘price’ => $price
    )
    )

    );

    $cashSale = new nsComplexObject(“CashSale”, $cashSaleFields);
    print_r($cashSale->getFields());

    $addResponse = $myNSclient->add($cashSale);

    if ( !$addResponse->isSuccess ) {

    $success = false;

    } else {

    $success = true;

    }

  11. stagg says:

    I figured it out. For anyone else in the world searching my code above is basically correct. I needed to build the paymentMethod differently than just supplying the int to the cashSaleFields

    ‘paymentMethod’ => array(‘internalId’ =>$paymentMethod),

  12. dreamxtream says:

    dreamxtream
    you are awesome!

    Could I ask for an example to condition for the date created – this seems to be another pain point I can seem to get correct?

    Thanks you so very much, you saved me HOURS!!

  13. shelly warren says:

    This post is terrific, your answers are spot on – thank you!
    I need to create a search that conditions a set of customer records based on the jobtype value of a project/job:
    $customerSearch = new nsComplexObject(“CustomerSearchBasic”);
    $jobSearch = new nsComplexObject(“JobSearchBasic”);
    $jobSearch->setFields(array(‘searchValue’ => array(new nsListOrRecordRef(array(‘internalId’ => 1)),
    new nsListOrRecordRef(array(‘internalId’ => 2)),
    new nsListOrRecordRef(array(‘internalId’ => 3))
    ),
    ‘internalId’ => ‘jobType’,
    ‘operator’ => ‘anyOf’));
    $searchItemFields = array (‘jobType’ => $jobSearch);
    $customerSearch->setFields($searchItemFields);

    This is not working, can anyone tell me what I missed or how to get the joined search to work?
    Thanks in advance!

  14. shelly warren says:

    Here is the second try – using your example, I feel like I am so close and yet… so far…
    $searchAdvance = new nsComplexObject(‘CustomerSearchAdvanced’);
    $search = new nsComplexObject(‘CustomerSearch’);

    $searchBasic = new nsComplexObject(‘JobSearchBasic’);
    $searchMultiSelectField = new nsComplexObject(‘SearchMultiSelectField’);
    //$searchValue = new nsRecordRef(array(‘type’ => ‘jobType’, ‘internalId’ => 1));
    $searchMultiSelectField->setFields( array( ‘operator’=>’noneOf’,
    ‘searchValue’=>new nsRecordRef(array(‘type’ => ‘jobType’, ‘internalId’ => 1)),
    new nsRecordRef(array(‘type’ => ‘jobType’, ‘internalId’ => 2)),
    new nsRecordRef(array(‘type’ => ‘jobType’, ‘internalId’ => 3))
    ));
    $searchBasic->setFields(array(‘jobType’=>$searchMultiSelectField));
    $joinFields = array(‘jobJoin’=>$searchBasic);

    $search->setFields($joinFields);

    $searchAdvance->setFields(array(‘criteria’=>$search));
    $searchResponse = $myNSclient->search($searchAdvance);

  15. dreamxtream says:

    @shelly warren
    What error NetSuite/PHP is throwing for your code?

  16. shelly warren says:

    @dreamxtream
    I am seeing no error – the result set is not being effected as I expect. Does this mean the code above looks accurate to you? Again – thank you for your time!

  17. Shane says:

    Found it: It is “is”. Why wont NetSuite publish good docs!

  18. alex says:

    Hi there,
    Can you provide an example with filter on dates like dateCreated ?
    Thanks so much !!!

  19. dreamxtream says:

    @alex

    You can use following operators for dates
    after, before, isempty, notafter, notbefore, noton, notonorafter, notonorbefore, notwithin, on, onorafter, onorbefore, within

    a sample call is given below

    new nlobjSearchFilter(‘trandate’,null,’notafter’,new Date())

  20. alex says:

    @dreamxtream
    Thanks for your help !
    I’m stuck with another call : GetDeletedFilter
    This is what I’ve done so far :

    $searchhandle = new nsComplexObject(“GetDeletedFilter”);
    $formated_date = “2011-11-01T00:16:17Z”;
    $filter[“deletedDate”] = array(“operator” => ‘onOrAfter’, “searchValue” => $formated_date);
    $filter[“type”] = array(“searchValue” => “salesOrder”);
    $searchhandle->setFields($filter);
    $results = $myNSclient->search($searchhandle);

    It doesn’t seem to work ? cheers 🙂

  21. Great post. NetSuite PHP has been a challenging and frustrating experience for me. I’ve had to work with custom record types alot which isn’t supported well in the toolkit netsuite gives you, I’ve wrapped alot of the more generic code I’ve used into a library on github https://github.com/iloveitaly/netsuite-kohana. Hope it helps someone out.

  22. alberto says:

    Not sure if you are still around, but having a hell of trouble getting the following: I would like to return all products (items) associated with a category. Building a front-end web site and trying to integrate with netsuite. Using your contact example here is what I have so far…Any help is appreciated. Thanks.


    $searchAdvance = new nsComplexObject('SiteCategorySearchAdvanced');
    $search = new nsComplexObject('SiteCategorySearch');

    $searchBasic = new nsComplexObject('SiteCategorySearchBasic');
    $searchMultiSelectField = new nsComplexObject('SearchMultiSelectField');
    $searchValue = new nsRecordRef(array('type' => 'siteCategory', 'internalId' => $categoryID));

    $searchMultiSelectField->setFields( array( 'operator'=>'anyOf','searchValue'=>$searchValue));
    $searchBasic->setFields(array('internalId'=>$searchMultiSelectField));

    $joinFields = array('basic'=>$searchBasic);
    $search->setFields($joinFields);

    $searchAdvance->setFields(array('criteria'=>$search));
    $searchResponse = $myNSClient->search($searchAdvance);

    var_dump($searchResponse);
    exit;

    Gives me the following error:

    Fatal error: Call to a member function search() on a non-object in C:\inetpub\wwwroot\partsforscooters.com\category2.php on line 48

  23. dreamxtream says:

    @alberto

    Have you created the $NSClient object using this code
    $myNSClient = new nsClient( nsHost::live );
    $myNSClient->setPassport($email, $password, $account,$role);

  24. Aubrey W says:

    Hello dreamxtream,
    Thank you for your examples and apparent willingness to help people out on your blog. I have a problem I’m hoping you could help me with. I am working on a script that pulls some information in from external systems and updates a custom field in customer records for billing purposes. My current problem is that I’m trying to find the next billing date for the customer so I can reset the counts that are being pulled in from the external systems. Each customer has a memorized transaction that auto-bills them at monthly intervals. I can pull up the memorized transactions in netsuite and get the next date, but I need to do this programmatically. There doesn’t appear to be a MemorizedTransactionSearch[Basic|Advanced] search type, but there is one for TransactionSearch[Basic|Advanced]. To start out I’ve been just trying to get all transactions associated with a customer and figure out from there how to filter down to just the memorized ones and then pull out the nextdate field to get what I want. I’ve used your contactJoin example as a starting point, but I’m not able to get an accurate list of transactions. Do you have any insight that could help me here? Below is an example of what I’ve tried. I’ve tinkered with most of the variables but no luck.

    $customerInternalId = XXXXXXX;

    $myNSclient->setSearchPreferences(false, 10);

    $search = new nsComplexObject(“TransactionSearchBasic”);

    $searchAdvance = new nsComplexObject(‘TransactionSearchAdvanced’);
    $search = new nsComplexObject(‘TransactionSearch’);

    $searchBasic = new nsComplexObject(‘CustomerSearchBasic’);
    $searchMultiSelectField = new nsComplexObject(‘SearchMultiSelectField’);
    $searchValue = new nsRecordRef(array(‘type’ => ‘customer’, ‘internalId’ => $customerInternalId));
    $searchMultiSelectField->setFields( array( ‘operator’=>’anyOf’,’searchValue’=>$searchValue));
    $searchBasic->setFields(array(‘internalId’=>$searchMultiSelectField));
    $joinFields = array(‘customerJoin’=>$searchBasic);
    $search->setFields($joinFields);
    $searchAdvance->setFields(array(‘criteria’=>$search));
    $searchResponse = $myNSclient->search($searchAdvance);

    var_dump($searchResponse);

    This gets me the following output, but if I look in netsuite there are several transactions for that customer, including memorized ones.

    # php getTrans.php

    PHP Notice: Undefined property: stdClass::$pageSize in /root/develop/netsuite/PHPtoolkit.php on line 425
    PHP Notice: Undefined property: stdClass::$pageIndex in /root/develop/netsuite/PHPtoolkit.php on line 427
    PHP Notice: Undefined property: stdClass::$record in /root/develop/netsuite/PHPtoolkit.php on line 432
    PHP Notice: Undefined property: stdClass::$record in /root/develop/netsuite/PHPtoolkit.php on line 443
    object(nsSearchResponse)#17 (9) {
    [“isSuccess”]=>
    bool(true)
    [“statusDetail”]=>
    NULL
    [“totalRecords”]=>
    int(0)
    [“pageSize”]=>
    NULL
    [“totalPages”]=>
    int(0)
    [“pageIndex”]=>
    NULL
    [“searchId”]=>
    string(60) “XXXXXXXXXX”
    [“recordList”]=>
    NULL
    [“searchRowList”]=>
    NULL
    }

  25. Sharique Abdullah says:

    @Aubrey W

    Did you make sure the customerId you are using is correct. That is, it should be a correct internal id of an existing customer which does have some transactions associated.

  26. Sharique Abdullah says:

    @Aubrey W

    Or may be you can try this one:

    $search = new nsComplexObject(“TransactionSearchBasic”);
    $fields =array(“entity” => array(“operator” => “anyOf”, “searchValue” => new nsRecordRef(array(‘internalId’ => $customerInternalId, ‘type’ =>’customer’))));
    $search->setFields($fields);
    $searchResponse = $myNSClient->search($search);

    var_dump($searchResponse);

  27. Aubrey W says:

    I’m sure about the customerId. I tried your code as well and get the same results. However, if I go in to NetSuite GUI and do Lists > Search > Saved Search > New, choose “Transaction” for the search type, and then add a criteria field of “Customer (Main Line) Fields… > InternalId” and set it to the same thing I have in my code, I get back plenty of results. I added a Results column of “Customer (Main Line) Fields… > InternalId” and verified in the results that the internalId of the customer for the transaction matches what I expect. Additionally, I can go to the System Notes for the customer I’m looking at and see the internal id is what I expect. I’m baffled.

  28. Greg says:

    Nice post

  29. Greg says:

    Hi. Would you happen to have a Sales Order sample that you could share?
    I have a could here that I’m trying to add a New Sales Order but I get this error “Invalid Entity Reference Key”

    $order_date = date(‘Y-m-d H:i:s’);
    $customer_id = $this->input->post(‘internalID’);

    // create array of fields
    $purchaseOrderFields = array (
    ‘entity’ => array (‘internalId’ => $customer_id),
    ‘itemList’ => array (
    ‘item’ => array (
    array(‘item’ => array(‘internalId’ => 116), ‘quantity’ => 1)
    )
    )
    );

    $salesOrder = new nsComplexObject(‘PurchaseOrder’);

    // set fields
    $salesOrder ->setFields($purchaseOrderFields);

    $addResponse = $myNSclient->add($salesOrder );

    Any Ideas and Insights are much appreciated. Thank you.

  30. dreamxtream says:

    @Greg
    It seems that the $customer_id your are providing is not correct. Use the code below to add the entity.
    ‘entity’ => new nsRecordRef(array(‘internalId’ => $customer_id, ‘type’ => ‘customer’)),

    Also make sure that the customer you are referring is NOT marked as inactive.

  31. Greg says:

    @dreamxtream
    I tried the code that you gave but I still having the same error
    “nsStatusDetail Object ( => INVALID_KEY_OR_REF [message] => Invalid entity reference key 1095”

    1095 is the internalID of the record that I wanted to add a Sales Order

    $order_date = date(‘Y-m-d H:i:s’);
    $customer_id = $this->input->post(‘internalID’);

    // create array of fields
    $purchaseOrderFields = array (
    ‘entity’ => new nsRecordRef(array(‘internalId’ => $customer_id, ‘type’ => ‘customer’)),
    ‘itemList’ => array (
    ‘item’ => array (
    array(‘item’ => array(‘internalId’ => 116), ‘quantity’ => 1)
    )
    )
    );

    // create purchase order record
    $purchaseOrder = new nsComplexObject(‘PurchaseOrder’);

    // set fields
    $purchaseOrder->setFields($purchaseOrderFields);

    // this will create a purchase order with 1 line item
    $addResponse = $myNSclient->add($purchaseOrder);

    Is there any other things that I missed that causing this error?

    Thank you for your reply..I really appreciate it..

  32. Greg says:

    Hi,
    Do I need to link a Customer record to a Vendor so that I can add Sales Order?

  33. dreamxtream says:

    @Greg
    You are saving a Purchase Order record not a Sales order Record. For Purchase Orders we need a vendor as an Entity so you can’t enter a customer id in that.

  34. Greg says:

    I see and regarding with adding Sales Order, why I got “Invalid Entity Reference Key” error even if I tried the samples of the PHP_toolkit. It supposed to be working. Is this something to do with my NetSuite Account that causes this error?

    These is the codes from the PHP_toolkit but still I’m having “Invalid Entity Reference Key”.
    setPassport($email, $password, $account, “14”);

    $salesOrderFields = array(

    ‘entity’ => new nsRecordRef(array(‘internalId’ => $entity)),
    ‘paymentMethod’ => array(‘internalId’ =>$paymentMethod),
    ‘ccNumber’ => $ccNumber,
    ‘ccExpireDate’ => date(“c”, mktime(0,0,0,$month,1,$year)),
    ‘ccName’ => $ccName,

    ‘itemList’ => array(
    ‘item’ => array(
    ‘item’ => array(‘internalId’ => $itemIntId),
    ‘quantity’ => $quantity
    )
    )

    );

    $salesOrder = new nsComplexObject(“SalesOrder”, $salesOrderFields);

    $addResponse = $myNSclient->add($salesOrder);

    if ( !$addResponse->isSuccess ) {

    $success = false;

    } else {

    $success = true;

    }
    ?>

    I really having a hard time with this. My head is about to explode.
    Is there anything I missed or anything that I need to configure in my NS Account?

    Thank you to all your replies. I am really thankful and appreciate it.

  35. dreamxtream says:

    Yes, there is a chance that it’s a account specific problem.

  36. Greg says:

    do you think only role administrator is the only role that can make this work? because the account that Im using is not administrator. Its a custom role.

  37. dreamxtream says:

    You can view the roles allowed to your custom role on Netsuite Site.

    Navigate to Setup ->User & Roles -> Manage Roles
    Go to Your Custom Role page and see permissions for Sales Order under Transaction Tab and Webservices under Setup Tab.

    Alternatively you can try different customers or operations to see if its working for you or not.

    Without access to actual account its difficult for anyone to diagnose the problems in NetSuite, So you have to try different things to detect the problem.

  38. Greg says:

    Hi,
    I tried to use an Account with an Administrator Role with the PHP_toolkit.
    And when I tried to run the PHP_toolkit Webstore sample, I still get “Invalid Entity Reference Key”.

    My head is exploding and my nose is bleeding with this error.
    I’m having a hard time figuring this out.

    Any Ideas and help will be awesome..
    @dreamxtream, thanks a lot..

  39. dreamxtream says:

    @Greg I can take a look at your script working. But for that I need your account credentials.

  40. Greg says:

    Hi dreamxtream,
    I think I found out that its an account role issue. When I tried to use the Admin Role, I never encountered the Invalid Entity Reference Key error but I got new error which is a USER_ERROR because I did not fill out the mandatory field, and on this case it was Channel (class) field.

    Do you have samples in adding Sales Orders with Channel (class) field?

    Thank you dreamxtream

  41. dreamxtream says:

    @Greg
    Although I don’t have a working sample for it but I think it should be something like this

    'class' => new nsRecordRef(array('internalId' => $classId, 'type' => 'class')),

  42. Greg says:

    @dreamxtream
    Thank You so Much..

  43. Greg says:

    Hello,
    In adding Sales Order, How can I add multiple Items or products? This is my code where I can only add 1 item.

    $salesOrderFields = array(
    ‘entity’ => new nsRecordRef(array(‘internalId’ => $entity)),
    ‘class’ => new nsRecordRef(array(‘internalId’ => $classId)),
    ‘paymentMethod’ => array(‘internalId’ =>$paymentMethod),
    ‘ccNumber’ => $ccNumber,
    ‘ccExpireDate’ => date(“c”, mktime(0,0,0,$month,1,$year)),
    ‘ccName’ => $ccName,
    ‘itemList’ => array(
    ‘item’ => array(
    ‘item’ => array(‘internalId’ => $itemIntId),
    ‘quantity’ => $quantity,
    ‘amount’ => $amount
    )
    )

    );

    $salesOrder = new nsComplexObject(“SalesOrder”, $salesOrderFields);
    $addResponse = $myNSclient->add($salesOrder);

    How can I add multiple products or items? Thank you so much.

  44. dreamxtream says:

    Try this sample

    ‘itemList’ => array(
    ‘item’ => array(
    ‘item’ => array(‘internalId’ => $itemIntId),
    ‘quantity’ => $quantity,
    ‘amount’ => $amount
    ),
    ‘item’ => array(
    ‘item’ => array(‘internalId’ => $itemIntId2),
    ‘quantity’ => $quantity2,
    ‘amount’ => $amount2
    )

    )

  45. Greg says:

    Hi dreamxtream,

    Thank you for your reply.

    I tried the sample you gave but the first item array was overwritten by the second item array. Only the second item array reflected in the NetSuite UI.

  46. dreamxtream says:

    @Greg
    Sorry for faulty code. That code was definitely not going to work. Although I don’t have a working sample for this but try adding all the items in item field. sort of code below

    'itemList'  => array(
        'item' => array(
            array(
                'item' => array('internalId' => $itemIntId),
                'quantity' => $quantity,
                'amount' => $amount
            ),
            array(
                'item' => array('internalId' => $itemIntId2),
                'quantity' => $quantity2,
                'amount' => $amount2
            )
        )
    )
    
  47. i.tect says:

    Hi,

    You can try this code.

    This works for me.

    ‘itemList’ => array(
    ‘item’ => array(
    array(
    ‘item’ => array(‘internalId’ => $itemIntId),
    ‘quantity’ => $quantity),
    array(
    ‘item’ => array(‘internalId’ => itemIntId2),
    ‘quantity’ => $quantity2)

    )
    )

  48. i.tect says:

    Hi,

    Anyone here tried to get all the item records through php???

  49. dgmdan says:

    Thanks for the great examples. I’m trying to search transactions and filter on the “applying transaction : date” which is different than the transaction’s tranDate. Any idea how to accomplish this?

  50. dreamxtream says:

    Have you tried “applyingTransactionJoin”. The code should look something like this.


    $tranDate = '2012-09-27T04:49:37.000-07:00';
    $filterFields = new nsComplexObject('SearchDateField');
    $filterFields->setFields(array("operator" => "onOrAfter", "searchValue" => $tranDate));

    $filterSearchBasic = new nsComplexObject('TransactionSearchBasic');
    $filterSearchBasic->setFields(array('tranDate' => $filterFields));

    $fields['applyingTransactionJoin'] = $filterSearchBasic;

    $search = new nsComplexObject('TransactionSearch');
    $search->setFields($fields);
    $searchResponse = $myNSclient->search($search);

  51. Manoj says:

    I want to get the Sales orders after a given internalId , and the Status is not closed.
    Do you have a sample code to use multiple fields in the condition to fetch the Sales Order ?
    Thanks in advance.

  52. is it possible to rank contacts under customers to a new field to be able to pull in a search all the rank one contacts?

  53. Manoj says:

    I get the results of my saved search with the following code, but when i uncomment the line below, to pass the tranDate as the criteria , it throws error : Fatal error: Uncaught exception ‘Exception’ with message ‘ was not found in directory. Argument = TransactionSearchAdvanced/tranDate’ in ….
    Am I using the criteria parameter incorrectly ?

    $myNSclient->setSearchPreferences(true, 10);
    $searchAdvanced = new nsComplexObject(‘TransactionSearchAdvanced’);
    $searchAdvanced->setFields(array(‘savedSearchId’=>’810’));

    //$searchAdvanced->setFields(array(‘tranDate’=>array(‘operator’ => ‘onOrAfter’, ‘searchValue’ => ‘2012-12-11T00:00:00’)));

    $searchResponse = $myNSclient->search($searchAdvanced);
    $totalRecords = $searchResponse->totalRecords;

    echo “

    ".print_r($searchResponse,true)."

    “;

  54. dreamxtream says:

    Below is the working code snippet to do the same. Hope it helps.


    $basicSearch = new nsComplexObject('TransactionSearchBasic',
    array('tranDate' => array('operator' => 'onOrAfter', 'searchValue' => '2012-12-11T00:00:00')));

    $transactionSearch = new nsComplexObject('TransactionSearch', array('basic' => $basicSearch));
    $advanceFields = array('savedSearchId' => '810', 'criteria' => $transactionSearch);
    $searchAdvanced = new nsComplexObject('TransactionSearchAdvanced', $advanceFields);

    $searchResponse = $myNSclient->search($searchAdvanced);

  55. Manoj says:

    Excellent. Its working fine. Thanks a lot.
    I tried the following , which worked fine, but your code is better than that. Thanks , it really helped.

    $tranDateCriteria = new nsComplexObject(“SearchDateField”);
    $tranDateCriteria->setFields(array(‘searchValue’ => ‘2012-12-11T16:44:57.000Z’,’operator’ => ‘on’)); //

    $tranSearchBasic = new nsComplexObject(“TransactionSearchBasic”);
    $tranSearchBasic->setFields(array(“tranDate” => $tranDateCriteria));

    $tranSearch = new nsComplexObject(“TransactionSearch”);
    $tranSearch->setFields(array(“basic” => $tranSearchBasic));

    $searchFields = array(‘savedSearchId’ => ‘810’,’criteria’ => $tranSearch);
    $tranSearchAdvanced = new nsComplexObject(“TransactionSearchAdvanced”);
    $tranSearchAdvanced->setFields($searchFields);
    $searchResponse = $myNSclient->search($tranSearchAdvanced);

  56. Manoj says:

    I use $myNSclient->setSearchPreferences(true, 1000); which gives me first 1000 records, and the number of pages.
    What is the best approach to walk through the entire set of results , instead of the first 1000 ?

    I know, there is the function ‘searchMore’ , but I am not sure how to use that to loop through the other pages.
    Thanks for the help.

  57. dreamxtream says:

    @Manoj
    You can use
    $myNSclient->searchMoreWithId($searchId,$pageNum);

    where $searchId is the searchId returned in the response of $myNSclient->search

  58. Manoj says:

    Wow, You are awesome. It worked flawlessly .
    Thanks n Regards

  59. Anonymous says:

    I’m trying to search customer records including custom fields, but I can’t figure out how to search based on custom fields. Every example I have found, developers are using a class nsComplexObject, and my PHPToolKit from netsuite does not contain this class. Any help regarding custom field searching with customer records?

    Thanks!

  60. dreamxtream says:

    As mentioned in the end of the post, Netsuite has done a lot of refactoring in 2012_2. You can use still use the old library as its not going to be deprecated soon. Download it from here

    Below is the excerpt of the code, which can be used to search on the basis of custom fields.


    $fieldToSearchArray[] = new nsListOrRecordRef(array('typeId' => '24', 'internalId' => $fieldToSearch));
    $multiSelect = new nsComplexObject('SearchMultiSelectCustomField', array(
    'internalId' => 'custevent_recordid',
    'operator' => 'anyOf',
    'searchValue' => $fieldToSearchArray));

    $fields['basic']['customFieldList']['customField'] = array($multiSelect);
    $search->setFields($fields);

  61. Andrew says:

    I’m hoping you can help me out here, as I am at the end of my tether!

    In the project I have (which I got given with no Netsuite knowledge whatsoever when it was nearly complete), customers are attached to companies. Companies have access to specific items. We’re getting this list of items just fine, but each customer has a custom record attached to them which gives a unique approval code for each item. If they do not have an approval code, they should not be able to access item details (documents etc.).

    I’m just completely stuck on how to access this value.

    I’m currently getting a list of all items a company can access, then looping over them to get the internal ID of the item (which is a custom field)

    The custom record type details attached to each company that I need to access are:

    ID – customrecord_custitem
    Internal ID – 1

    It has 3 fields, IDs are – custrecord_lookup_customer (which is company ID), custrecord_lookup_item (current item ID in the loop) and custrecord_custitem_code. It is this last one that I need to access.

    Can you point me in the right direction here? I noticed that an internalId of 260 is used to get the items a user has access to, can I add something to this to also return the custrecord_custitem_code, or do I need to duplicate this and loop through with the proper recType internalId?

    $search = $this->netsuite->complexObject(‘CustomRecordSearchBasic’)->setFields(array(
    ‘recType’ => new nsCustomRecordRef(array(
    ‘internalId’ => 260,
    ‘type’ => ‘customRecord’)
    ),
    ‘customFieldList’ => array($companySearch)
    ));

    Sorry it’s a long one!

  62. Have you ever considered writing an ebook or guest authoring on
    other sites? I have a blog based on the same ideas you discuss and would
    really like to have you share some stories/information.
    I know my visitors would enjoy your work. If you are even remotely interested, feel free to send
    me an e-mail.

  63. Bo Alexander says:

    Interesting blog. I have tried to scan it to see if it answers my question, but I haven’t spotted it.

    I am using C#, not php.

    I’m trying to figure out how to enumerate the custom field (names and types) defined for various record types (like Case or Contact for example, but really anything). I know these can vary by site, so I know I have to query Netsuite at runtime. In fact, I can enumerate the custom fields once I have a record from a search

    foreach CustomFieldRef cf in supportCase.customFieldList)

    and I see the internalId strings (example: “custevent_vc_techid”). But they seem to be prefixed by some strange text (example: “custevent_vc_”), not sure if that is a netsuite thing, or how my NetSuite administrator defined them. I’d like to get the “short name” or label used on forms (example: “techie”), if it exists in the custom field definition for that entity. Does it? How can I get that (I considered if get all() might help me, but I don’t know how to use it.)

    Also, I have only managed to get that list once I have retrieved a record. Is there a way to retrieve the custom field list definitions (internalId, type, and perhaps the form label used with that field?), withOUT retrieving some actual case data record?

    Thanks in advance for any pointers you can provide. Cheers. Bo.

  64. Ali shan says:

    Hey i was adding adding a SaleOrder from the Netsuite API but i am getting the error. can any one have the example code. Thanks

  65. Tony says:

    I am new to NetSuite and trying out the toolkit. My goal is to convert our store locator from php->MySQL to php->NetSuite. When I try to run the test code from the phptoolkit, I get errors that indicate that my php on my host is not SOAP enabled. Anybody know how to compile php to handle SOAP?

  66. dreamxtream says:

    @Tony PHP SOAP is a PHP Extension. Any extension can be enabled in PHP using php.ini file.

    Open the php.ini file for your PHP installation
    Find the line “php_soap.dll”
    uncomment this line (remove the ; from beginning)
    Restart PHP

  67. Shubham says:

    I want to search the transactions “Sales Orders” and “Transfer Orders” jointly. The following conditions work fine separately without any problem. I want to join these to make a single call.

    Can you help in joining these ?
    Thanks.

    $transactionsearch = new nsComplexObject(‘TransactionSearchBasic’);
    $transactionsearch->setFields( array( ‘type’ => array( ‘operator’ => ‘anyOf’, ‘searchValue’ => “_salesOrder” ),
    ‘internalIdNumber’ => array( ‘operator’ => ‘greaterThan’, ‘searchValue’ => $last_id),
    ‘status’ => array( ‘operator’ => ‘anyOf’, ‘searchValue’ => ‘_salesOrderPendingFulfillment’),
    ‘paymentEventResult’ => array(‘operator’ => ‘noneOf’, ‘searchValue’ => ‘_paymentHold’),
    ‘customFieldList’ => array ($CustomBodyField1,$CustomBodyField2,$CustomBodyField3)
    ));

    OR

    $transactionsearch = new nsComplexObject(‘TransactionSearchBasic’);
    $transactionsearch->setFields( array( ‘type’ => array( ‘operator’ => ‘anyOf’, ‘searchValue’ => “transferOrder” ),
    ‘internalIdNumber’ => array( ‘operator’ => ‘greaterThan’, ‘searchValue’ => $last_id),
    ‘status’ => array( ‘operator’ => ‘anyOf’, ‘searchValue’ => ‘_transferOrderPendingFulfillment’),
    ‘customFieldList’ => array ($CustomBodyField2)
    ));

  68. krishan says:

    Hi, I want to know how to create folder in the netsuite api using netsuite php toolkit.
    Please help me.
    Thank you

  69. Stu says:

    Hi im trying to ouput the row data in a customer saved search via webservices.. im failing to pull through the row data can you point me in the right direction.

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

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

    if (!$searchResponse->searchResult->status->isSuccess) {
    echo “SEARCH ERROR”;
    } else {
    echo “SEARCH SUCCESS, records found: ” . $searchResponse->searchResult->totalRecords . “\n”;

    $records = $searchResponse->searchResult->searchRowList->searchRow->CustomerSearchRowBasic;

    foreach ($records as $record) {
    //echo “Name: ” . $record->basic->name->searchValue . “\n”;
    echo “Number: ” . $accountNumber . “\n”;
    }

    }

  70. công ty xây dựng nhà giá rẻ Và quý khách đang cân nhắc tìm
    một công ty xây dựng uy tín với chuyên môn cao để tân trang lại ngôi nhà, Xây dựng Hòa Hưng
    chính là sự lựa chọn số 1 cho khách hàng với nhiều dịch vụ ưu đãi.… Chúng tôi sẽ hổ trợ giúp
    bạn xây nhà Theo kiến trúc sư Công ty Xây dựng Hòa Hưng
    cho biết, thông thường đơn giá xây nhà
    trọn gói sẽ bao gồm nhiều hạng mục, nhưng chủ yếu phụ thuộc vào 3
    yếu tố sau…. công ty chúng tôi chuyên xây
    nhà đẹp Đơn giá thi công được áp dụng
    cho quy trình thi công bao gồm chi phí giám sát và quản lý công trình, cũng như tất cả các khoản bảo hiểm của nhà thầu và bên thứ ba…..
    đống đa hà nội Có rất nhiều lý do để quý khách làm mới lại căn hộ của mình như: ngôi nhà quá cũ, các hạng mục xuống
    cấp, chuyển nhà, mua nhà mới,.… các công ty
    xây dựng lớn tại tphcm
    xay nha binh duong

  71. I am glad to be one of the visitants on this great internet site (:, regards
    for posting.

  72. 閲覧数 says:

    I wanted to follow up and let you know how , very much I appreciated discovering this blog today.
    I’d personally consider it the honor to operate at my office and be able
    to make real use of the tips provided on your site and also engage in visitors’
    feedback like this. Should a position connected with guest author become offered at your end, remember
    to let me know.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: