Tuesday, December 18, 2018

PHP Toolkit 2012.2 Sample Code: Add a new record for a custom record type

Customer created a new record type on Setup > Customization > Record Types and named it as "Basic Record Type"
with internal ID = 14 and he want to create a new record for this custom record using PHP Web Services

Below is a sample code on how to add new record for a custom record type using PHP Toolkit 2012.2

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

$service = new NetSuiteService();
//add a new record for a custom record type

//create an instance of the fields of the custom record
$customFieldList = new StringCustomFieldRef();
$customFieldList->internalId = "custrecord_name"; //Use 'internalId' if using the 2012.2 WSDL-Toolkit//$customFieldList->scriptId = "custrecord_name"; //Use 'scriptId' if using the 2013.2 WSDL-Toolkit
$customFieldList->value = "Test from PHP toolkit";

$basicCustomRecord = new CustomRecord();
$basicCustomRecord->name = "PHP Toolkit 2012.2";
$basicCustomRecord->recType = new RecordRef();
$basicCustomRecord->recType->internalId = "14"; //Record Type's internal ID (Setup > Customization > Record Types > Basic Record Type (Internal ID=14)
$basicCustomRecord->customFieldList = new CustomFieldList();
$basicCustomRecord->customFieldList->customField = $customFieldList;

$addRequest = new AddRequest();
$addRequest->record = $basicCustomRecord;

$addResponse = $service->add($addRequest);

if (!$addResponse->writeResponse->status->isSuccess) {
    echo "ADD ERROR";
} else {
    echo "ADD SUCCESS, id " . $addResponse->writeResponse->baseRef->internalId;

No comments:

Post a Comment