How can I retrieve the Online Price for Inventory Items using ItemSearch?
I have built an external web site and I'm simply trying to import Item info for all Online Items in NetSuite into my database. I'm stuck on the Price. There is a PricingMatrix and a PriceList for each Item but I'm not sure how this all fits together and I have not yet found anything useful in these forums or in the documentation for NetSuite Web Services.
I can successfully run an ItemSearch and I check the results to find only the items that are true for IsOnline (perhaps there is a better way but I'll get to that later).
I'm writing all this in C#..
private void itemSearch() { itemCount = 0; login(); // NetSuite Log In ItemSearch itemSearch = new ItemSearch(); SearchStringField name = new SearchStringField(); name.@operator = SearchStringFieldOperator.contains; name.operatorSpecified = true; name.searchValue = ""; SearchEnumMultiSelectField type = new SearchEnumMultiSelectField(); String[] inv = new String[1]; // TODO: inv[0] = ItemType.__inventoryItem; inv[0] = "_inventoryItem"; type.@operator = SearchEnumMultiSelectFieldOperator.anyOf; type.operatorSpecified = true; type.searchValue = inv; ItemSearchBasic itemBasic = new ItemSearchBasic(); itemBasic.type = type; itemBasic.name = name; //itemSearch.setType(type); //itemSearch.setName(name); itemSearch.basic = itemBasic; SearchPreferences sprefs = new SearchPreferences(); sprefs.bodyFieldsOnly = true; //needed to get price info this._service.searchPreferences = sprefs; SearchResult res = _service.search(itemSearch); if (res.status.isSuccess) { Record[] recordList; if (res.totalRecords > 0) { for (int i = 1; i <= res.totalPages; i++) { recordList = res.recordList; for (int j = 0; j < recordList.Length; j++) { if (recordList[j] is InventoryItem) { InventoryItem item = (InventoryItem)(recordList[j]); if (item.isOnline == true && item.isInactive == false) { displayInventoryItemFields(item, out internalId,out storeOnlinePrice, out storeDisplayName, out storeDescription, out storeDetailedDescription, out storeDisplayThumbnail, out storeDisplayImage); DataSet1 ds = new DataSet1(); DataSet1TableAdapters.inventoryitemsTableAdapter tInvItms = new DataSet1TableAdapters.inventoryitemsTableAdapter(); tInvItms.Fill(ds.inventoryitems); DataRow[] dr = ds.inventoryitems.Select("internalId=" + internalId); if (dr.Length > 0) { bool locked = false; try { locked = Boolean.Parse(dr[0]["locked"].ToString()); } catch (Exception) { } if (locked == false) { dr[0]["internalId"] = internalId; dr[0]["storeOnlinePrice"] = storeOnlinePrice; dr[0]["storeDisplayName"] = storeDisplayName; dr[0]["storeDescription"] = storeDescription; dr[0]["storeDetailedDescription"] = storeDetailedDescription; dr[0]["storeDisplayThumbnail"] = storeDisplayThumbnail; dr[0]["storeDisplayImage"] = storeDisplayImage; tInvItms.Update(dr[0]); } } else { DataRow newrow = ds.inventoryitems.NewRow(); newrow["internalId"] = internalId; newrow["storeOnlinePrice"] = storeOnlinePrice; newrow["storeDisplayName"] = storeDisplayName; newrow["storeDescription"] = storeDescription; newrow["storeDetailedDescription"] = storeDetailedDescription; newrow["storeDisplayThumbnail"] = storeDisplayThumbnail; newrow["storeDisplayImage"] = storeDisplayImage; newrow["localcategory"] = 0; ds.inventoryitems.Rows.Add(newrow); tInvItms.Update(ds.inventoryitems); } } } } if (res.pageIndex < res.totalPages) { res = _service.searchMore(i + 1); } } } } else { lblOutput.Text += (getStatusDetails(res.status)); } logout(); // NetSuite Log Out lblOutput.Text = itemCount.ToString() + " items updated.<br>"; GridView1.DataBind(); } private void displayInventoryItemFields(InventoryItem item, out int internalId, out int storeOnlinePrice, out string storeDisplayName, out string storeDescription, out string storeDetailedDescription, out string storeDisplayThumbnail, out string storeDisplayImage) { internalId = 0; storeOnlinePrice = 0; storeDisplayName = ""; storeDescription = ""; storeDetailedDescription = ""; storeDisplayThumbnail = ""; storeDisplayImage = ""; if (item != null) { if (item.storeDisplayName != null) { storeDisplayName = item.storeDisplayName.ToString(); } if (item.internalId != null) { internalId = int.Parse(item.internalId.ToString()); } if (item.storeDescription != null) { storeDescription = item.storeDescription.ToString(); } if (item.storeDetailedDescription != null) { storeDetailedDescription = item.storeDetailedDescription.ToString(); } if (item.storeDisplayThumbnail != null) { storeDisplayThumbnail = item.storeDisplayThumbnail.name.ToString(); } if (item.storeDisplayImage != null) { storeDisplayImage = item.storeDisplayImage.name.ToString(); } itemCount++; // HERE IS WHERE I AM STUCK // HERE IS WHERE I AM STUCK // HERE IS WHERE I AM STUCK PricingMatrix pm = new PricingMatrix(); pm = item.pricingMatrix; if (pm != null) { Pricing[] pricing = pm.pricing; string ps = string.Empty; for (int i = 0; i < pricing.Length; i++) { ps += "int_id[" + item.internalId.ToString() + "] = " + pricing[i].priceList[0].value.ToString() + Environment.NewLine.ToString(); } myStreamWriter(Server.MapPath("pMatrix.config"), ps); } } } Can anyone help me find the simplest way to retrieve Online Price for my Inventory Items?Thanks,Rob Woodhttp://www.somadream.com