Netsuite allows an administrator to add custom fields and custom records via GUI. Custom fields are business specific attributes defined by the company to tailor Netsuite. When a custom field is created in Netsuite, the administrator will assign an ID of the custom field and this ID becomes internal ID of the custom field. To show internal ID on Netsuite GUI, it must be turned on by going to Home -> Set Preferences -> General -> Defaults, and checking "Show Internal IDs" checkbox.
To illustrate with an example, lets assume that we defined a custom field called "custbody_admin" in the Purchase Order record type. Let's also assume that the value of "custbody_admin" is an employee type record. Let say we want to write a function that will take a PO number as an input, and return email address of the "custbody_admin" (employee).
public function getAdminEmail($po) { global $myNSclient; $adminEmail = null; // Search for a purchase order from a PO number. $search = new nsComplexObject("TransactionSearchBasic"); $type = new nsComplexObject('SearchEnumMultiSelectField'); $type->setFields(array('searchValue' => array('_purchaseOrder'), 'operator' => 'anyOf')); $params = new nsComplexObject('SearchStringField'); $params->setFields(array('searchValue' => $poId, 'operator' => 'is')); $search->setFields(array ('type' => $type, 'tranId'=> $params)); $response = $myNSclient->search($search); if ($response->isSuccess) { $poObj = $response->recordList[0]; // Get the custom field list from the purchase order. $customFieldList = $poObj->getField('customFieldList'); $processor = null; // Loop through the custom field list, and search for the // custbody_admin (employee) record foreach ($customFieldList->getField('customField') as $customField) { if ("custbody_admin" == $customField->getField('internalId')) { $processor = $customField->getField('value'); $id = $processor->getField('internalId'); $recordRefs = array( new nsRecordRef(array("internalId" => $id, "type" => "employee"))); $recordList = $myNSclient->getList($recordRefs); $employee = $recordList[0]->record; $adminEmail = $employee->getField('email'); } } } return $adminEmail; }
Comments
Add new comment