Reputation: 5522
Hoping someone here has NetSuite experience! I am accessing a saved search through the Netsuite webservice to retrieve Sales Orders. For some reason, the items on the order come through as:
[item] => Array
(
[0] => SearchColumnSelectField Object
(
[searchValue] => RecordRef Object
(
[internalId] => 1088
[externalId] =>
[type] =>
[name] =>
)
It is not displaying the product code, but instead internalId, even though the saved search on screen correctly displays the product. How can I get the product code from this?
Upvotes: 1
Views: 1394
Reputation: 127
<?php
$order_date = date('Y-m-d H:i:s');
// create array of fields
$itemArr = array();
$i = 0;
foreach($order_items_product as $keyProduct =>$valueProduct){
//if you not have internal id of item in netsuuite then please add the item in the netsuite and try.
$netsuiteItemId = 'Your Item Internal id Which is in the Netsuite Item';
$itemArr[$i]['item']['internalId'] = $netsuiteItemId;
$itemArr[$i]['quantity'] = $valueProduct['qty'];
$i++;
}
if (!define('LF', "\n")) {
define('LF', "\n");
}
/* for use in formatting custom addresses since NetSuite converts to <br> */
//Billing Address Information
/* this example has the customer address info in a db record, just pulled into $row */
$billAddress = stripslashes($order->order_custom_fields['_billing_first_name'][0]) . ' ' . $order->order_custom_fields['_billing_last_name'][0] . LF;
$billAddress .= stripslashes($order->order_custom_fields['_billing_address_1'][0]).LF;
$billAddress .= stripslashes($order->order_custom_fields['_billing_address_2'][0]).LF;
$billAddress .= stripslashes($order->order_custom_fields['_billing_country'][0]).LF;
$billAddress .= stripslashes($order->order_custom_fields['_billing_state'][0]) . ' - ' . $order->order_custom_fields['_billing_postcode'][0] . ', ' . LF;
$billAddress .= $order->order_custom_fields['_billing_phone'][0] . ', ' . $order->order_custom_fields['_billing_email'][0];
//Shipping Address Information
$shipAddress = stripslashes($order->order_custom_fields['_shipping_first_name'][0]) . ' ' . $order->order_custom_fields['_shipping_last_name'][0] . LF;
$shipAddress .= stripslashes($order->order_custom_fields['_shipping_address_1'][0]).LF;
$shipAddress .= stripslashes($order->order_custom_fields['_shipping_address_2'][0]).LF;
$shipAddress .= stripslashes($order->order_custom_fields['_shipping_city'][0]).LF;
$shipAddress .= stripslashes($order->order_custom_fields['_shipping_state'][0]) . ', ' . $order->order_custom_fields['_shipping_postcode'][0] . ', ' . LF;
$shipAddress .= $order->order_custom_fields['_billing_phone'][0] .', '. $order->order_custom_fields['_billing_email'][0];
$purchaseOrderFields = array (
'entity' => array ('internalId' => $internal_Id, 'type' => 'customer'),
'shippingCost' => $order->order_shipping,
'shipMethod' => $order->payment_method,
'toBeEmailed' => true,
//'tranId' => $order->order_custom_fields['Transaction ID'][0],
//'tranDate' => date('Y-m-d H:i:s'),
'source' => 'littlecrate',
'createdFrom' => 'littlecrate.com',
'discountRate' => $order->order_custom_fields['_order_discount'][0],
'taxRate' => $order->order_custom_fields['_order_tax'][0],
'email' => $order->billing_email,
//'shipDate' => date('Y-m-d H:i:s'),
'shipMethod' => $order->shipping_method,
'shippingCost' => $order->order_shipping,
'shippingTax1Rate' => $order->order_shipping_tax,
'paymentMethod' => $order->payment_method,
//'taxTotal' => $order->order_tax,
//'total' => $order->order_total,
'billAddress' => $billAddress,
'shipAddress' => $shipAddress,
'itemList' => array (
'item' => $itemArr
)
);
$salesOrder = new nsComplexObject('SalesOrder');
$salesOrder ->setFields($purchaseOrderFields);
$addResponse = $myNSclient->add($salesOrder );
if (!$addResponse->isSuccess) {
echo "Order Information is Not Inserted Into The Netsuite. Please Contact to Administration.";
exit;
}
?>
Upvotes: 0
Reputation: 1164
Set bodyFieldsOnly to FALSE in your search preferences.
$NSservice = new NetSuiteService();
$NSservice->setSearchPreferences(false, 100, true);
Upvotes: 0
Reputation: 1633
You're picking the wrong column and/or searching for a field value rather than the text or itemfield:name instead. I'll edit my answer and add more as I find it. This is from my ns experiences though with suitescript.
using the referencedocs I see: Posting TRX summary field:
<complexType name="PostingTransactionSummaryField">
<sequence>
<element name="period" type="xsd:boolean" minOccurs="0" maxOccurs="1"/>
<element name="account" type="xsd:boolean" minOccurs="0" maxOccurs="1"/>
<element name="parentItem" type="xsd:boolean" minOccurs="0" maxOccurs="1"/>
<element name="item" type="xsd:boolean" minOccurs="0" maxOccurs="1"/>
<element name="entity" type="xsd:boolean" minOccurs="0" maxOccurs="1"/>
<element name="department" type="xsd:boolean" minOccurs="0" maxOccurs="1"/>
<element name="class" type="xsd:boolean" minOccurs="0" maxOccurs="1"/>
<element name="location" type="xsd:boolean" minOccurs="0" maxOccurs="1"/>
<element name="subsidiary" type="xsd:boolean" minOccurs="0" maxOccurs="1"/>
</sequence>
</complexType>
or also using the referencedocs I see: GetPostingTransactionSummaryResult:
<complexType name="GetPostingTransactionSummaryResult">
<sequence>
<element ref="platformCore:status" minOccurs="1" maxOccurs="1"/>
<element name="totalRecords" type="xsd:int" minOccurs="0"/>
<element name="pageSize" type="xsd:int" minOccurs="0"/>
<element name="totalPages" type="xsd:int" minOccurs="0"/>
<element name="pageIndex" type="xsd:int" minOccurs="0"/>
<element name="postingTransactionSummaryList" type="platformCore:PostingTransactionSummaryList" minOccurs="0" maxOccurs="1"/>
</sequence>
</complexType>
On a seperate unrelated topic, I found this:
Specifying Web Services Context
To cause a form to behave differently in Web Services versus the UI, you can do one of the following:
Write context-specific SuiteScript code and use the nlapiGetContext function to branch the code
Disable SuiteScript in Web services
However, both Client and Server SuiteScripts are written to enforce customized business rules that may need to be enforced regardless of the mechanism by which a record is created or updated within NetSuite. This is particularly true for customers who deploy a SuiteCloud partner application and want to be sure their business rules are still respected. Since Client SuiteScript often has browser-specific behavior that requires user action and cannot automatically run during a Web Services call, NetSuite recommends that you disable Client SuiteScript and deploy Server SuiteScript for those business conditions that need to be enforced in all cases.
To specify that Server SuiteScript should never execute during a Web services call, enable the Disable Server-side Scripting preference on the Web Services Preference page at Setup > Integration > Web Services.
Important:
Only enable this preference when data submitted via Web services does NOT need to adhere to custom business logic and workflows that may be executed via Server SuiteScript.
Upvotes: 1