Sometimes, I surprise myself. Over the course of my 20 year technology career, I’ve never really found a technical problem I couldn’t eventually figure out. I’ve become a master of the Google search and a freakishly thorough consumer of the NetSuite Users Group web site.
But while trying to work with the Related Items sublist within the Inventory Item object in NetSuite’s Web Services, “SuiteTalk”, I was almost ready to throw in the towel. I ran into a couple of problems:
1. The documentation for SuiteTalk is pretty thorough, and the SuiteTalk Schema Browser is ultra helpful in almost all situations. However, the object representing the Related Items sublist, the PresentationItem object, is conspicuously absent from both.
2. The RecordRef object, one of the fundamental cores of SuiteTalk, is an object I know inside and out, just like any good SuiteTalk programmer. However, when using it with this sublist, I was getting errors in the responses to my SuiteTalk requests.
I tried everything – I double and triple checked both my code and the data I was trying to process. But with no documentation for the PresentationItem object, I was at a bit of a loss. Finally, I just decided to dig through the SuiteTalk WSDL and figure it out the old fashioned way. Here’s what I found:
The Inventory Item is defined in the Accounting XSD. Inside the definition for Inventory Item, I found the related items sublist, which is called Presentation Items. After a bit of searching through the XSD, I finally found the PresentationItemList complex type, which is the container that holds the individual Presentation Items. I was hot on the trail! But this really doesn’t tell me much, other than the List will contain zero or more Presentation Items, and that you can specify whether to replace all the items in the list or just add to the ones already existing.
<complexType name=”PresentationItemList”>
<sequence>
<element name=”presentationItem” type=”platformCommon:PresentationItem” minOccurs=”0″ maxOccurs=”unbounded”/>
</sequence>
<attribute name=”replaceAll” type=”xsd:boolean” default=”true”/>
</complexType>
But the one piece of information here that was a huge help in my quest, was that the Presentation Item itself was defined in “platformCommon”. So I go and dig up the
Common XSD. With a quick search of the Common XSD, there it was… The undocumented Presentation Item object!
<complexType name=”PresentationItem”>
<sequence>
<element name=”item” type=”platformCore:RecordRef” minOccurs=”0″/>
<element name=”itemType” type=”platformCommonTyp:PresentationItemType” minOccurs=”0″/>
<element name=”description” type=”xsd:string” minOccurs=”0″/>
<element name=”onlinePrice” type=”xsd:double” minOccurs=”0″/>
<element name=”basePrice” type=”xsd:double” minOccurs=”0″/>
</sequence>
</complexType>
And there’s that RecordRef object that I knew had to be there. I coded up a loop that would read the ExternalIDs of items from the 3rd party system I was working with, and created a RecordRef for each one, appending the RecordRef to my array of RecordRefs as I went along. I also found the list of acceptible itemTypes, which the PresentationItem required. I was all ready to test and rock and roll…
But NetSuite rejected my RecordRef objects, saying I could not use ExternalIDs. How could this be??? I’ve used ExternalIDs with RecordRef objects 1000 times. I quickly coded up a GET statement using my RecordRef in order to grab the actual record from NetSuite. Then, I was able to get the InternalID of the record and use that in a new RecordRef object.
Once I plugged in that InternalID, BAM! I had my Related Items sublist populating. Here’s the PHP code for those who run into the same problem:
$itemItemList = new PresentationItemList();
$itemItemList->replaceAll = true;
sqlsrv_execute($dsItemItems);
$q = 0;
while ($dsItemItem = sqlsrv_fetch_object($dsItemItems)) {
$itemRR = new RecordRef();
$itemRR->externalId = $dsItemItem->ProdID;
$itemRR->type = “inventoryItem”;
$request = new GetRequest();
$request->baseRef = $itemRR;
$getResponse = $NSservice->get($request);
if ($getResponse->readResponse->status->isSuccess) {
$internalId = $getResponse->readResponse->record->internalId;
$itemRR = new RecordRef();
$itemRR->internalId = $internalId;
$itemRR->type = “inventoryItem”;
$itemItem = new PresentationItem();
$itemItem->item = $itemRR;
$itemItem->itemType = “_item”;
$itemItemList->presentationItem[] = $itemItem;
$q++;
}
}
print_r(“Processed ” . $q . ” related items\n”);
$item = new InventoryItem();
$item->externalId = $dsItem->externalId;
$item->presentationItemList = $itemItemList;
$request = new UpdateRequest();
$request->record = $item;
$upsertResponse = $NSservice->update($request);
Like this:
Like Loading...