Thursday, December 20, 2018

Coding Comparison between PHP Toolkit 2012.2 and old versions

 

 

 

PHP Toolkit 2012.2

Lower Versions

Record object initialization.

Each record type can now be initialized using the same record type name as stated on the NetSuite Schema Browser.

 

Example, to initialize a Customer record object:

$CustomerRec = new Customer();

Initialize the object using nsComplexObject.

 

Example, to initialize a Customer record object:

$CustomerRec = new nsComplexObject('Customer');

Object Type Initialization

 

All object types are listed and explained on:

SuiteCloud (Customization, Scripting, and Web Services) : SuiteTalk (Web Services) : SuiteTalk (Web Services) Platform Information : Types : Platform Enumerations

 

Each complex, search and custom field types are initialized using the same object type name as noted on the NetSuite Schema Browser:

 

To initialize a basic search for customers:

$search = new CustomerSearchBasic();

 

To initialize a recordRef object:

$selectTypeField = new RecordRef();

These objects are initialized using the object nsComplexObject.

 

To initialize a basic search for customers:

$search = new nsComplexObject('CustomerSearchBasic');

 

To initialize a recordRef object:

$selectTypeField = new nsComplexObject('RecordRef');

Calling the NetSuite SuiteTalk (Web Services) operations

The operations are called from the service object instantiated from the NetSuiteService class (NetSuiteService.php).

 

Example:

$service = new NetSuiteService();

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

The operations are called from the client object instantiated from the nsClient class (declared on the phptoolkit.php).

 

Example:

$myNSclient = new nsClient( nsHost::live );

$addResponse = $myNSclient->add($contact);

 

Request object

A request object needs to be initialized depending on the kind of operation. This request object will accept the Record object, which will then be set to the operation. Each operation has a corresponding request type. Example:

AddRequest for add operation

AddListRequest for  addList operation

SearchRequest for search operation.

 

Example, to add a customer:

$service = new NetSuiteService();

$CustomerRec = new Customer();

$request = new AddRequest();

$request->record = $CustomerRec;

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

 

None. The record object is directly set to the operation.

 

Example, to add a customer:

$CustomerRec = new nsComplexObject('Customer');

$addResponse = $myNSclient->add($CustomerRec);

 

The setFields method

A function to set an array of field objects to the record object.

 

Example:

$customerRec = new Customer();

$customerFields = array (

              'isPerson' => true,

              'firstName' => $firstName,

              'lastName' => $lastName,

              'companyName' => $companyName

);

 

setFields($customerRec, $ customerFields);

This is a method of the record object used to set the array of field values to the record.

 

Example:

$customerFields = array (

              'isPerson' => true,

              'firstName' => $firstName,

              'lastName' => $lastName,

              'companyName' => $companyName

);

// create Customer record

$customer = new nsComplexObject('Customer');

// set fields

$customer->setFields($customerFields);

Setting Search Request Preferences

Use the setSearchPreferences method. There are 2 parameters:
1.  bodyFieldsOnly
2.  pageSize

 

Example:

$service = new NetSuiteService();

 

$service->setSearchPreferences(false, 20);

 

The above sample set bodyFieldsOnly to false and PageSize to 20.

The setSearchPreferences method already exists in the old PHP
Toolkit. Same with 2012.2, there are 2 parameters:
1. bodyFieldsOnly
2. pageSize

 

Example:

$service = new NetSuiteService();

 

$service->setSearchPreferences(false, 20);

 

The above sample set bodyFieldsOnly to false and PageSize to 20.

Setting Request Preferences for non-search requests.

Use the addHeader method. There are 2 parameters needed:

1. the header name, in this case it's 'preferences'

2. A preferences object

 

Example:

$service = new NetSuiteService();

$preferences = new Preferences();

$preferences->ignoreReadOnlyFields = TRUE;

$preferences->warningAsError = FALSE;

 

$service->addHeader("preferences", $preferences);

 

Use the setPreferences method. These are parameters:

1. ignoreReadOnlyFields

2. warningAsError

3. disableMandatoryCustomFieldValidation

4. disableSystemNotesForCustomFields

5. useConditionalDefaultsOnAdd

6. useConditionalDefaultsOnUpdate

 

Example:

$myNSclient->setPreferences(FALSE, FALSE, TRUE, TRUE, TRUE, TRUE);

No comments:

Post a Comment