Reputation: 4438
So far I have created two methods for obtaining Sales Order object. One is get by customer id, the other is get by transaction id, or transId. Both methods are returning the Sales Orders but the itemList is always null. When I check in NetSuite there are in fact Sales order items.
I found this thread, that mentioned making sure that bodyFieldsOnly was set to false. I'm not positive I am setting this attribute properly but I am attempting to do so.
Here are both of my methods, if anyone has any insight I would appreciate it. I've already spent a while trying to solve this one.
// Get sales order by tranId
public function getSalesOrder($sales_order_trans_id)
{
$service = new NetSuiteService(self::_config);
$search = new TransactionSearchBasic();
$searchStringField = array('searchValue' => $sales_order_trans_id,
'operator' => 'is');
$search->tranId=$searchStringField;
$request = new SearchRequest();
$searchPreferences = new SearchPreferences();
$searchPreferences->bodyFieldsOnly = false;
$request->searchPreferences = $searchPreferences;
$request->searchRecord = $search;
return $searchResponse = $service->search($request)->searchResult->recordList->record;
}
And the resulting Sales Order object converted to array, dumped looks like this:
```array:1 [▼
0 => SalesOrder {#175 ▼
+createdDate: "2016-08-09T15:30:31.000-07:00"
+customForm: null
+entity: RecordRef {#176 ▶}
+job: null
+currency: null
+drAccount: null
+fxAccount: null
+tranDate: "2016-08-09T00:00:00.000-07:00"
+tranId: "SO4326"
+source: null
+createdFrom: null
+orderStatus: null
+opportunity: null
+salesRep: null
+contribPct: null
+partner: null
+salesGroup: null
+syncSalesTeams: false
+leadSource: RecordRef {#177 ▶}
+startDate: null
+endDate: null
+otherRefNum: null
+memo: null
+salesEffectiveDate: "2016-08-09T00:00:00.000-07:00"
+excludeCommission: null
+totalCostEstimate: null
+estGrossProfit: null
+estGrossProfitPercent: null
+exchangeRate: null
+promoCode: null
+currencyName: null
+discountItem: null
+discountRate: null
+isTaxable: null
+taxItem: null
+taxRate: null
+toBePrinted: false
+toBeEmailed: false
+email: "[email protected]"
+toBeFaxed: false
+fax: null
+messageSel: null
+message: null
+billingAddress: Address {#1 ▶}
+billAddressList: null
+shippingAddress: Address {#1 ▶}
+shipIsResidential: false
+shipAddressList: null
+fob: null
+shipDate: null
+actualShipDate: null
+shipMethod: null
+shippingCost: null
+shippingTax1Rate: null
+isMultiShipTo: null
+shippingTax2Rate: null
+shippingTaxCode: null
+handlingTaxCode: null
+handlingTax1Rate: null
+handlingTax2Rate: null
+handlingCost: null
+trackingNumbers: null
+linkedTrackingNumbers: null
+shipComplete: null
+paymentMethod: null
+shopperIpAddress: null
+saveOnAuthDecline: true
+creditCard: null
+revenueStatus: "_pending"
+recognizedRevenue: 0.0
+deferredRevenue: 0.0
+revRecOnRevCommitment: null
+revCommitStatus: null
+ccNumber: null
+ccExpireDate: null
+ccName: null
+ccStreet: null
+ccZipCode: null
+payPalStatus: null
+creditCardProcessor: null
+payPalTranId: null
+ccApproved: null
+getAuth: null
+authCode: null
+ccAvsStreetMatch: null
+ccAvsZipMatch: null
+isRecurringPayment: null
+ccSecurityCodeMatch: null
+altSalesTotal: null
+ignoreAvs: null
+paymentEventResult: null
+paymentEventHoldReason: null
+paymentEventType: null
+paymentEventDate: null
+paymentEventUpdatedBy: null
+subTotal: 444.99
+discountTotal: null
+taxTotal: null
+altShippingCost: null
+altHandlingCost: null
+total: 444.99
+revRecSchedule: null
+revRecStartDate: null
+revRecEndDate: null
+paypalAuthId: null
+balance: null
+paypalProcess: null
+billingSchedule: null
+ccSecurityCode: null
+threeDStatusCode: null
+class: null
+department: RecordRef {#1 ▶}
+subsidiary: RecordRef {#1 ▶}
+intercoTransaction: null
+intercoStatus: null
+debitCardIssueNo: null
+lastModifiedDate: "2016-08-09T15:30:31.000-07:00"
+location: null
+pnRefNum: null
+status: "Pending Approval"
+tax2Total: null
+terms: RecordRef {#182 ▶}
+validFrom: null
+vatRegNum: null
+giftCertApplied: null
+oneTime: null
+recurWeekly: null
+recurMonthly: null
+recurQuarterly: null
+recurAnnually: null
+tranIsVsoeBundle: null
+vsoeAutoCalc: null
+syncPartnerTeams: null
+salesTeamList: null
+partnersList: null
+giftCertRedemptionList: null
+promotionsList: null
+itemList: null
+shipGroupList: null
+accountingBookDetailList: null
+customFieldList: CustomFieldList {#183 ▶}
+internalId: "1"
+externalId: null
+nullFieldList: null
}
]```
The other method, get a customers Sales ORders by customer Id.
public function getCustomerSalesOrders($customer_id)
{
$service = new NetSuiteService(self::_config);
$customerSearchBasic = new CustomerSearchBasic();
$searchValue = new RecordRef();
$searchValue->type = 'customer';
$searchValue->internalId = $customer_id;
$searchMultiSelectField = new SearchMultiSelectField();
setFields($searchMultiSelectField, array('operator' => 'anyOf', 'searchValue' => $searchValue));
$customerSearchBasic->internalId = $searchMultiSelectField;
$transactionSearchBasic = new TransactionSearchBasic();
$prefs = new Preferences();
$service->preferences = $prefs;
$searchPreferences = new SearchPreferences();
$searchPreferences->bodyFieldsOnly = false;
$service->searchPreferences = $searchPreferences;
$searchMultiSelectEnumField = new SearchEnumMultiSelectField();
setFields($searchMultiSelectEnumField, array('operator' => 'anyOf', 'searchValue' => "_salesOrder"));
$transactionSearchBasic->type = $searchMultiSelectEnumField;
$transactionSearch = new TransactionSearch();
$transactionSearch->basic = $transactionSearchBasic;
$transactionSearch->customerJoin = $customerSearchBasic;
$request = new SearchRequest();
$request->searchRecord = $transactionSearch;
$searchResponse = $service->search($request);
return $searchResponse->searchResult->recordList->record;
}
Upvotes: 1
Views: 3461
Reputation: 116
If you want to get the items from a transaction search, you have to set your search preferences so that bodyFieldsOnly
is not true. Unfortunately, you didn't set it properly in your code. This is what you should update:
$service = new NetSuiteService(self::_config);
$service->setSearchPreferences(false, 50, true);
The first argument is bodyFieldsOnly
. Set that to false, and the itemList will be included.
Upvotes: 0
Reputation: 1
Im getting this:
GetResponse Object ( [readResponse] => ReadResponse Object ( [status] => Status Object ( [statusDetail] => Array ( [0] => StatusDetail Object ( [code] => INVALID_TRANS_TYP [message] => Transaction type specified is incorrect. [afterSubmitFailed] => [type] => ERROR ) ) [isSuccess] => ) [record] => ) )
Trying this:
$service = new NetSuiteService();
$request = new GetRequest();
$request->baseRef = new RecordRef();
$request->baseRef->internalId = 7007; //<< REPLACE THIS WITH YOUR INTERNAL ID
$request->baseRef->type = 'salesOrder';
$getResponse = $service->get($request);
Upvotes: 0
Reputation: 3029
You are using a search. Use this instead:
$service = new NetSuiteService();
$request = new GetRequest();
$request->baseRef = new RecordRef();
$request->baseRef->internalId = 123456; //<< REPLACE THIS WITH YOUR INTERNAL ID
$request->baseRef->type = 'salesOrder';
$getResponse = $service->get($request);
Upvotes: 6