Tuesday, December 18, 2018

PHP Toolkit 2012.2 Sample Code: Ability to get the values of Custom Fields

Below is a sample code that will display the ids and the values of all custom fields
in the Employee record.

<?php

require_once '../NSPHPClient/NetSuiteService.php';

$service = new NetSuiteService();

$request = new GetRequest();
$request->baseRef = new RecordRef();
$request->baseRef->internalId = 12802;
$request->baseRef->type = "employee";
$getResponse = $service->get($request);

if (!$getResponse->readResponse->status->isSuccess) {
    echo "GET ERROR";
} else {
    $employee = $getResponse->readResponse->record;
    echo "GET SUCCESS, customer:";
    echo "\nCompany name: ". $employee->companyName;
    echo "\nInternal Id: ". $employee->internalId;
    echo "\nEmail: ". $employee->email;
    //custom field
    $customFieldListListArray = $employee->customFieldList->customField;
    
    
    if (is_array($customFieldListListArray))
    {
        foreach ($customFieldListListArray as $customField)
        {
                //var_dump(get_class($customField));
                echo $customField->internalId . " : ";
                $customFieldObjectType = get_class($customField);
                if ( $customFieldObjectType == "BooleanCustomFieldRef" ) {
                echo $customField->value  === true ? "true" : "false";
                } elseif ( $customFieldObjectType == "DateCustomFieldRef" ) {
                echo $customField->value;
                } elseif ( $customFieldObjectType == "DoubleCustomFieldRef" ) {
                echo $customField->value;
                } elseif ( $customFieldObjectType == "LongCustomFieldRef" ) {
                echo $customField->value;
                } elseif ( $customFieldObjectType == "MultiSelectCustomFieldRef" ) {
                } elseif ( $customFieldObjectType == "StringCustomFieldRef" ) {
                echo $customField->value;
                } elseif ( $customFieldObjectType== "SelectCustomFieldRef" ) {
                echo $customField->value->internalId;
                }

        }     
    }
    }
?>

 

No comments:

Post a Comment