Web Services: How to get list of sales tax items
Note: This article applies to the PHPToolkit prior to 2012.2.
To get a list of all the Sales Tax Items using web services, we can use the getSelectValue operation on a customer record specifying the field 'taxitem'.
Here's a sample SOAP request that gets the list of all the Sales Tax Items.
<soapenv:Body>
<platformMsgs:getSelectValue
xmlns:platformCoreTyp="urn:types.core_2011_2.platform.webservices.netsuite.com"
xmlns:platformCore="urn:core_2011_2.platform.webservices.netsuite.com"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:platformMsgs="urn:messages_2011_2.platform.webservices.netsuite.com">
<platformMsgs:fieldDescription>
<platformCore:recordType>customer</platformCore:recordType>
<platformCore:field>taxitem</platformCore:field>
</platformMsgs:fieldDescription>
<platformMsgs:pageIndex>0</platformMsgs:pageIndex>
</platformMsgs:getSelectValue>
</soapenv:Body>
Please see below sample script written in PHP and .Net invoking the getSelectValue operation to get the list.
PHP sample script
require_once '../PHPtoolkit.php';
require_once 'login_info.php';
global $myNSclient;
set_time_limit(0);
// Initialize fields for the getSelectValue request
$getSelectValueRequest = new nsComplexObject("GetSelectValueFieldDescription");
$getSelectValueRequest->setFields(array("recordType"=>"customer","field"=>"taxitem"));
// Execute getSelectValue operation
$getSelectValueResponse = $myNSclient->getSelectValue($getSelectValueRequest,0);
if (!$getSelectValueResponse->isSuccess) {
echo "<font color='red'><b>ERROR: " . $getSelectValueResponse->statusDetail[0]->message . "</b></font>";
} else {
// Loop through all the values
echo "*** List of Sales Tax Items ***";
foreach ($getSelectValueResponse->baseRefList as $baseRef){
echo $baseRef->getField('name')." <==> ".$baseRef->getField('internalId')."<br/>";
}
}
.NET sample script
//Create the Netsuite Service object
NetSuiteService _service = new NetSuiteService();
_service.CookieContainer = new CookieContainer();
Passport passport = new Passport();
passport.account = "NAME_OF_ACCOUNT";
passport.email = "email_address_to_login_to_NetSuite";
RecordRef role = new RecordRef();
role.internalId = "3"; // 3 is the internalID for administrator role
passport.role = role;
passport.password = "password_in_NetSuite";
Status status = _service.login(passport).status;
_service.login(passport);
GetSelectValueFieldDescription Request_fields = new GetSelectValueFieldDescription();
Request_fields.recordTypeSpecified = true;
Request_fields.recordType = RecordType.customer;
Request_fields.field = "taxitem";
GetSelectValueResult result = _service.getSelectValue(Request_fields, 0);
BaseRef[] baseRef = result.baseRefList;
//Loop through all the values
for (int i = 0; i < result.totalRecords; i++){
Response.Write(baseRef[i].name + "<br />");
}
No comments:
Post a Comment