Below is a Sample of PHP code showing how to update custom columns of different types in the Sales Order Items list.
Since version 2013.2 Custom Fields can be referred to by their Internal ID and their Script ID.
<?phprequire_once 'PHPToolkit/NetSuiteService.php';$service = new NetSuiteService(); $SalesOrderId = '22817';$SalesOrderRecord = new SalesOrder(); // WSDL 2013.2 version requires that you use scriptID or InternalID //StringCustomFieldRef$aStringField = new StringCustomFieldRef();$aStringField->scriptId = 'custcol2';$aStringField->value = 'Testing string value'; // SelectCustomFieldRef$aSelectField = new SelectCustomFieldRef();$aSelectField->scriptId = 'custcol3';// refer the column field by Internal Id//$aSelectField->internalId = 39;$aSelectField->value = new ListOrRecordRef();$aSelectField->value->internalId = 87; // MultiSelectCustomFieldRef$aMSField = new MultiSelectCustomFieldRef();$lorr1 = new ListOrRecordRef();$lorr1->internalId = 87;$lorr2 = new ListOrRecordRef();$lorr2->internalId = 176;$aMSField->value = array($lorr1, $lorr2);$aMSField->scriptId = 'custcol4'; // DateCustomFieldRef$aDateField = new DateCustomFieldRef();$aDateField->scriptId = 'custcol5';$aDateField->value = date("c"); //the array of custom fields$customFieldList = new customFieldList();$customFieldList->customField = array($aStringField,$aSelectField,$aMSField,$aDateField); $SalesOrderItemList = new SalesOrderItemList();$SalesOrderItem = new SalesOrderItem();//we will set the custom fields for the first item$SalesOrderItem->line = 1;$SalesOrderItem->customFieldList = $customFieldList; $SalesOrderItemList->item = array($SalesOrderItem);$SalesOrderItemList->replaceAll = false;$SalesOrderRecord->itemList = $SalesOrderItemList; $SalesOrderRecord->internalId = $SalesOrderId; $updateRequest = new UpdateRequest();$updateRequest->record = $SalesOrderRecord;$updateResponse = $service->update($updateRequest); if ($updateResponse->status->isSuccess) echo 'Sales Order Update was Successful'; else echo 'Sales Order Update was not Successful';?>
The above code would generate the following SOAP Request:
<update> <record xsi:type="SalesOrder" internalId="22817"> <itemList replaceAll="false"> <item> <line>1</line> <customFieldList> <customField xsi:type="StringCustomFieldRef" scriptId="custcol2"> <value>Testing string value</value> </customField> <customField xsi:type="SelectCustomFieldRef" scriptId="custcol3"> <value internalId="87"/> </customField> <customField xsi:type="MultiSelectCustomFieldRef" scriptId="custcol4"> <value internalId="87"/> <value internalId="176"/> </customField> <customField xsi:type="DateCustomFieldRef" scriptId="custcol5"> <value>2013-11-18T18:45:26+01:00</value> </customField> </customFieldList> </item> </itemList> </record></update>
No comments:
Post a Comment