Wednesday, September 19, 2018

Web Service > PHPToolkit > Setting values to custom column fields code sample

 
The user wants to set values for custom column fields on a record (Sales Order for example).
 
Note: This article requires existing knowledge of Web Services and PHP.
 
 
The sample code below will update the sublist's (item sublist) custom column fields in a sales order record.

require_once '../PHPtoolkit.php';
require_once 'login_info.php';
 
global $myNSclient;
global $myDirectory;
 
$SalesOrderId = '175';
 
$SalesOrderRecord = new nsComplexObject('SalesOrder');
 
$BooleanCustomField = new nsComplexObject('BooleanCustomFieldRef');
$BooleanCustomField->setFields(array('internalId' => 'custcol_booleanfield', 'value' => true));
 
$DateCustomField = new nsComplexObject('DateCustomFieldRef');
$DateCustomField->setFields(array('internalId' => 'custcol_datefield', 'value' => '2010-02-11T20:36:40.659Z'));
 
$DoubleCustomField = new nsComplexObject('DoubleCustomFieldRef');
$DoubleCustomField->setFields(array('internalId' => 'custcol_doublefield', 'value' => '12.45'));
 
$LongCustomField = new nsComplexObject('LongCustomFieldRef');
$LongCustomField->setFields(array('internalId' => 'custcol_longfield', 'value' => '100'));
 
$SelectFieldValue = new nsComplexObject('ListOrRecordRef', array('internalId' => '1', 'typeId' => '24'));
$SelectCustomField = new nsComplexObject('SelectCustomFieldRef');
$SelectCustomField->setFields(array('value' => $SelectFieldValue, 'internalId' => 'custcol_selectfield'));
 
$StringCustomField = new nsComplexObject('StringCustomFieldRef');
$StringCustomField->setFields(array('internalId' => 'custcol_stringfield', 'value' => 'Testing'));
 
$salesOrderFields = array(
     'internalId' => $SalesOrderId,
     'itemList'  => array ( 
      'item' => array (
        array('line' => 1,
           'customFieldList' => array($BooleanCustomField, $DateCustomField, $DoubleCustomField, $LongCustomField, $SelectCustomField, $StringCustomField))),
     'replaceAll' => false));
 
$SalesOrderRecord -> setFields($salesOrderFields);
 
$updateResponse = $myNSclient->update($SalesOrderRecord); 
 
if ($updateResponse->isSuccess) {
 echo 'Update Successful'; 
}
 


 

The above code would generate this SOAP Request:

 <?xml version="1.0" encoding="UTF-8" ?>
- <Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:sales_2009_2.transactions.webservices.netsuite.com" xmlns:ns2="urn:core_2009_2.platform.webservices.netsuite.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns3="urn:messages_2009_2.platform.webservices.netsuite.com">
- <Body>
- <update>
- <record internalId="175" xsi:type="SalesOrder">
- <itemList replaceAll="false">
- <item>
  <line>1</line>
- <customFieldList>
- <customField internalId="custcol_booleanfield" xsi:type="BooleanCustomFieldRef">
  <value>true</value>
  </customField>
- <customField internalId="custcol_datefield" xsi:type="DateCustomFieldRef">
  <value>2010-02-11T20:36:40.659Z</value>
  </customField>
- <customField internalId="custcol_doublefield" xsi:type="DoubleCustomFieldRef">
  <value>12.45</value>
  </customField>
- <customField internalId="custcol_longfield" xsi:type="LongCustomFieldRef">
  <value>100</value>
  </customField>
- <customField internalId="custcol_selectfield" xsi:type="SelectCustomFieldRef">
  <value internalId="1" typeId="24" />
  </customField>
- <customField internalId="custcol_stringfield" xsi:type="StringCustomFieldRef">
  <value>Testing</value>
  </customField>
  </customFieldList>
  </item>
  </itemList>
  </record>
  </update>
  </Body>
  </Envelope>

No comments:

Post a Comment