Wednesday, April 24, 2019

Web Services > PHP Toolkit: Retrieve value of specific Custom Field from record

Sample PHP code that retrieves value of specific custom field (custitem_test) on Inventory Item record with ID 123.

Note:The following sample source code requires PHP Toolkit version 2012.2 orhigher.

require_once 'NetSuiteService.php';$service = new NetSuiteService(); $itemRef = new RecordRef();$itemRef->type = RecordType::inventoryItem;$itemRef->internalId = 123; $getRequest = new GetRequest();$getRequest->baseRef = $itemRef; $getResponse = $service->get($getRequest);$item = $getResponse->readResponse->record; if (!$getResponse->readResponse->status->isSuccess) {    die("GET error!");} else {    foreach ($item->customFieldList->customField as $field) { // loop through all custom fields        $fieldId = $field->internalId;        if ($fieldId == "custitem_test") {            $fieldValue = $field->value;            echo "Value of custom field '$fieldId': $fieldValue";        }    }    if (!$fieldValue)        echo "Field not found";}

No comments:

Post a Comment