예제 #1
1
function setFields($object, array $fieldArray = null)
{
    // helper method that allows creating objects and setting their properties based on an associative array passed as argument. Mimics functionality from PHP toolkit
    $classname = get_class($object);
    // a static map that maps class parameters to their types. needed for knowing which objects to create
    $typesmap = $classname::$paramtypesmap;
    if (!isset($typesmap)) {
        // if the class does not have paramtypesmap, consider it empty
        $typesmap = array();
    }
    if ($fieldArray == null) {
        // nothign to do
        return;
    }
    foreach ($fieldArray as $fldName => $fldValue) {
        if ((is_null($fldValue) || $fldValue == "") && $fldValue !== false || arrayValuesAreEmpty($fldValue)) {
            //empty param
            continue;
        }
        if (!isset($typesmap[$fldName])) {
            // the value is not a valid class atrribute
            trigger_error("SetFields error: parameter \"" . $fldName . "\" is not a valid parameter for an object of class \"" . $classname . "\", it will be omitted", E_USER_WARNING);
            continue;
        }
        if ($fldValue === 'false') {
            // taken from the PHP toolkit, but is it really necessary?
            $object->{$fldName} = false;
        } elseif (is_object($fldValue)) {
            $object->{$fldName} = $fldValue;
        } elseif (is_array($fldValue) && array_is_associative($fldValue)) {
            // example: 'itemList'  => array('item' => array($item1, $item2), 'replaceAll'  => false)
            if (substr($typesmap[$fldName], -2) == "[]") {
                trigger_error("Trying to assign an object into an array parameter \"" . $fldName . "\" of class \"" . $classname . "\", it will be omitted", E_USER_WARNING);
                continue;
            }
            $class = 'NetSuite\\Classes\\' . $typesmap[$fldName];
            $obj = new $class();
            setFields($obj, $fldValue);
            $object->{$fldName} = $obj;
        } elseif (is_array($fldValue) && !array_is_associative($fldValue)) {
            // array type
            if (substr($typesmap[$fldName], -2) != "[]") {
                // the type is not an array, skipping this value
                trigger_error("Trying to assign an array value into parameter \"" . $fldName . "\" of class \"" . $classname . "\", it will be omitted", E_USER_WARNING);
                continue;
            }
            // get the base type  - the string is of type <type>[]
            $basetype = substr($typesmap[$fldName], 0, -2);
            // example: 'item' => array($item1, $item2)
            foreach ($fldValue as $item) {
                if (is_object($item)) {
                    // example: $item1 = new nsComplexObject('SalesOrderItem');
                    $val[] = $item;
                } elseif ($typesmap[$fldName] == "string") {
                    // handle enums
                    $val[] = $item;
                } else {
                    // example: $item2 = array( 'item'      => new nsComplexObject('RecordRef', array('internalId' => '17')),
                    //                          'quantity'  => '3')
                    $class = 'NetSuite\\Classes\\' . $basetype;
                    $obj = new $class();
                    setFields($obj, $item);
                    $val[] = $obj;
                }
            }
            $object->{$fldName} = $val;
        } else {
            $object->{$fldName} = $fldValue;
        }
    }
}
<?php

require_once '../PHPToolkit/NetSuiteService.php';
$service = new NetSuiteService();
$purchaseOrderFields = array('entity' => array('internalId' => 1), 'itemList' => array('item' => array(array('item' => array('internalId' => 458), 'quantity' => 5)), 'replaceAll' => true));
$po = new PurchaseOrder();
setFields($po, $purchaseOrderFields);
$request = new AddRequest();
$request->record = $po;
$addResponse = $service->add($request);
if (!$addResponse->writeResponse->status->isSuccess) {
    echo "ADD ERROR";
} else {
    echo "ADD SUCCESS, id " . $addResponse->writeResponse->baseRef->internalId;
}
예제 #3
0
namespace NetSuite\WebServices;

require_once '../PHPToolkit/NetSuiteService.php';
$service = new NetSuiteService();
$service->setPassport($nsaccount = 'MYACCT1', $nsemail = '*****@*****.**', $nsrole = '3', $nspassword = '******');
$svr = new getSelectValueRequest();
$svr->fieldDescription = new GetSelectValueFieldDescription();
$svr->pageIndex = 1;
/*$svr->fieldDescription->recordType = RecordType::salesOrder;
$svr->fieldDescription->sublist = "itemList";
$svr->fieldDescription->field = "price";
$svr->fieldDescription->
*/
$priceFields = array('recordType' => RecordType::salesOrder, 'sublist' => 'itemList', 'field' => 'price', 'filterByValueList' => array('filterBy' => array(array('field' => 'item', 'sublist' => 'itemList', 'internalId' => '45'))));
setFields($svr->fieldDescription, $priceFields);
$gsv = $service->getSelectValue($svr);
$id = null;
foreach ($gsv->getSelectValueResult->baseRefList->baseRef as $pricelevel) {
    if ($pricelevel->name == 'Custom') {
        $id = $pricelevel->internalId;
        break;
    }
}
if ($id != null) {
    echo "Custom price level id is " . $id . "\n";
} else {
    echo "Custom price level not found " . $id . "\n";
}
$so = new SalesOrder();
$so->entity = new RecordRef();
<?php

require_once '../PHPToolkit/NetSuiteService.php';
$service = new NetSuiteService();
$service->setSearchPreferences(false, 20);
$noteSearchAdvance = new NoteSearchAdvanced();
$noteSearch = new NoteSearch();
$customerSearchBasic = new CustomerSearchBasic();
$searchValue = new RecordRef();
$searchValue->type = 'customer';
$searchValue->internalId = 21;
$searchMultiSelectField = new SearchMultiSelectField();
setFields($searchMultiSelectField, array('operator' => 'anyOf', 'searchValue' => $searchValue));
$customerSearchBasic->internalId = $searchMultiSelectField;
$noteSearch->customerJoin = $customerSearchBasic;
$noteSearchAdvance->criteria = $noteSearch;
$request = new SearchRequest();
$request->searchRecord = $noteSearchAdvance;
$searchResponse = $service->search($request);
if (!$searchResponse->searchResult->status->isSuccess) {
    echo "SEARCH ERROR";
} else {
    echo "SEARCH SUCCESS, records found: " . $searchResponse->searchResult->totalRecords;
}
?>

<?php

require_once '../PHPToolkit/NetSuiteService.php';
$service = new NetSuiteService();
$service->setSearchPreferences(false, 20);
$itemSearch = new ItemSearchBasic();
$searchItems = array('isInactive' => array('searchValue' => 'TRUE'));
setFields($itemSearch, $searchItems);
$request = new SearchRequest();
$request->searchRecord = $itemSearch;
$searchResponse = $service->search($request);
/*
 *  Issue 200500
$searchItems = array( 'isInactive' ,"value" => TRUE); //customer's command => is ignored and generates a request without isInactive filter
Now results in:
Warning: SetFields error: parameter "value" is not a valid parameter for an object of class ItemSearchBasic, it will be omitted
*/
if (!$searchResponse->searchResult->status->isSuccess) {
    echo "SEARCH ERROR";
} else {
    echo "SEARCH SUCCESS, records found: " . $searchResponse->searchResult->totalRecords;
}
?>

<?php

require_once '../PHPToolkit/NetSuiteService.php';
$service = new NetSuiteService();
$customer = new Customer();
$customerFields = array('firstName' => "Joe", 'lastName' => "Doe", 'companyName' => "ABC company", 'phone' => "123456789", 'email' => "*****@*****.**");
setFields($customer, $customerFields);
$request = new AddRequest();
$request->record = $customer;
$addResponse = $service->add($request);
if (!$addResponse->writeResponse->status->isSuccess) {
    echo "ADD ERROR";
} else {
    echo "ADD SUCCESS, id " . $addResponse->writeResponse->baseRef->internalId;
}
?>
 

<?php

namespace NetSuite\WebServices;

require_once '../PHPToolkit/NetSuiteService.php';
$service = new NetSuiteService();
$service->setPassport($nsaccount = 'MYACCT1', $nsemail = '*****@*****.**', $nsrole = '3', $nspassword = '******');
// create Customer record
$customer1 = new Customer();
$name = 'customer_php_async_1';
$customerFields1 = array('entityId' => $name, 'companyName' => $name, 'externalId' => $name);
setFields($customer1, $customerFields1);
$customer2 = new Customer();
$name2 = 'customer_php_async_2';
$customerFields2 = array('entityId' => $name2, 'companyName' => $name2, 'externalId' => $name2);
setFields($customer2, $customerFields2);
// perform async add operation
$asyncreq = new AsyncAddListRequest();
$asyncreq->record = array($customer1, $customer2);
$checkAsync = $service->asyncAddList($asyncreq);
// get job id
$jobId = $checkAsync->asyncStatusResult->jobId;
$checkasyncreq = new CheckAsyncStatusRequest();
$checkasyncreq->jobId = $jobId;
while ($checkAsync->asyncStatusResult->status == 'pending' || $checkAsync->asyncStatusResult->status == 'processing') {
    sleep(10);
    $checkAsync = $service->checkAsyncStatus($checkasyncreq);
}
// once it is done processing, get the result
$getasyncreq = new GetAsyncResultRequest();
$getasyncreq->jobId = $jobId;