public string createNewBin(InventoryBin bin) { NetSuiteService service = new NetSuiteService(); service.CookieContainer = new CookieContainer(); NetsuiteUser user = new NetsuiteUser("3451682", "*****@*****.**", "1026", "tridenT168"); Passport passport = user.prepare(user); Status status = service.login(passport).status; LocationSearch locationSearch = new LocationSearch(); LocationSearchBasic locationSearchBasic = new LocationSearchBasic(); SearchStringField locationName = new SearchStringField(); locationName.searchValue = bin.LocationName; locationName.@operator = SearchStringFieldOperator.@is; locationName.operatorSpecified = true; locationSearchBasic.name = locationName; locationSearch.basic = locationSearchBasic; SearchResult sr = new SearchResult(); sr = service.search(locationSearch); if (sr.status.isSuccess != true) Console.WriteLine(sr.status.statusDetail[0].message); Bin newBin = new Bin(); RecordRef newLocation = new RecordRef(); newLocation.type = RecordType.location; newLocation.typeSpecified = true; newLocation.internalId = ((com.netsuite.webservices.Location)sr.recordList[0]).internalId; newBin.binNumber = bin.BinNumber; newBin.location = newLocation; WriteResponse writeResponse = service.add(newBin); if (writeResponse.status.isSuccess == true) { Console.WriteLine("Bin: "+ newBin.binNumber +" has been created."); return "Bin: " + newBin.binNumber + " has been created."; } if (writeResponse.status.isSuccess == false) { Console.WriteLine(writeResponse.status.statusDetail[0].message); return writeResponse.status.statusDetail[0].message; } return string.Empty; }
public void DeleteBin(InventoryBin bin) { NetSuiteService service = new NetSuiteService(); service.CookieContainer = new CookieContainer(); NetsuiteUser user = new NetsuiteUser("3451682", "*****@*****.**", "1026", "tridenT168"); Passport passport = user.prepare(user); Status status = service.login(passport).status; BinSearch binSearch = new BinSearch(); BinSearchBasic bSBasic = new BinSearchBasic(); SearchStringField binName = new SearchStringField(); binName.searchValue = bin.BinNumber; binName.@operator = SearchStringFieldOperator.@is; binName.operatorSpecified = true; bSBasic.binNumber = binName; binSearch.basic = bSBasic; SearchResult sr = new SearchResult(); sr = service.search(binSearch); if (sr.status.isSuccess != true) Console.WriteLine(sr.status.statusDetail[0].message); RecordRef binToDelete = new RecordRef(); binToDelete.type = RecordType.bin; binToDelete.typeSpecified = true; binToDelete.name = bin.BinNumber; binToDelete.internalId = ((Bin)sr.recordList[0]).internalId; WriteResponse writeResponse = service.delete(binToDelete); if (writeResponse.status.isSuccess == true) { Console.WriteLine("Bin: " + binToDelete.name + " has been deleted."); } if (writeResponse.status.isSuccess == false) { Console.WriteLine(writeResponse.status.statusDetail[0].message); } }
public string addBin(InventoryBin itemBin) { NetSuiteService service = new NetSuiteService(); service.CookieContainer = new CookieContainer(); NetsuiteUser user = new NetsuiteUser("3451682", "*****@*****.**", "1026", "tridenT168"); Passport passport = user.prepare(user); Status status = service.login(passport).status; SearchStringField objItemName = new SearchStringField(); objItemName.searchValue = itemBin.InventoryItem.ItemName; objItemName.@operator = SearchStringFieldOperator.@is; objItemName.operatorSpecified = true; ItemSearch objItemSearch = new ItemSearch(); objItemSearch.basic = new ItemSearchBasic(); objItemSearch.basic.itemId = objItemName; SearchResult objItemResult = service.search(objItemSearch); if (objItemResult.status.isSuccess != true) { Console.WriteLine("Cannot find Item " + itemBin.InventoryItem.ItemName + " " + objItemResult.status.statusDetail[0].message); return "Cannot find Item " + itemBin.InventoryItem.ItemName + " " + objItemResult.status.statusDetail[0].message; } if (objItemResult.recordList.Count() != 1) { Console.WriteLine("More than one item found for item " + itemBin.InventoryItem.ItemName); return "More than one item found for item " + itemBin.InventoryItem.ItemName; } SearchStringField objBinNumber = new SearchStringField(); objBinNumber.searchValue = itemBin.BinNumber; objBinNumber.@operator = SearchStringFieldOperator.@is; objBinNumber.operatorSpecified = true; BinSearch objBinSearch = new BinSearch(); objBinSearch.basic = new BinSearchBasic(); objBinSearch.basic.binNumber = objBinNumber; SearchResult objBinResult = service.search(objBinSearch); if (objBinResult.status.isSuccess == false) { Console.WriteLine("Unable to find bin " + itemBin.BinNumber + " in NetSuite"); return "Unable to find bin " + itemBin.BinNumber + " in NetSuite"; } if (objItemResult.recordList.Count() != 1) { Console.WriteLine("More than one bin found for " + itemBin.BinNumber); return "More than one bin found for " + itemBin.BinNumber; } if (((Bin)objBinResult.recordList[0]).isInactive) { Console.WriteLine("Bin Number " + itemBin.BinNumber + " is inactive in NetSuite"); return "Bin Number " + itemBin.BinNumber + " is inactive in NetSuite"; } RecordRef objAddBin = new RecordRef(); objAddBin.type = RecordType.bin; objAddBin.typeSpecified = true; objAddBin.internalId = ((Bin)objBinResult.recordList[0]).internalId; objAddBin.name = ((Bin)objBinResult.recordList[0]).binNumber; InventoryItemBinNumber objItemBinNumber = new InventoryItemBinNumber(); objItemBinNumber.location = ((Bin)objBinResult.recordList[0]).location.internalId; objItemBinNumber.binNumber = objAddBin; InventoryItemBinNumber[] objItemBinNumbers = new InventoryItemBinNumber[1]; objItemBinNumbers[0] = objItemBinNumber; if(((InventoryItem)objItemResult.recordList[0]).useBins==true) { //Initialize item to update InventoryItem objInventoryItem = new InventoryItem(); objInventoryItem.internalId = ((InventoryItem)objItemResult.recordList[0]).internalId; objInventoryItem.salesDescription = ((InventoryItem)objItemResult.recordList[0]).salesDescription; objInventoryItem.purchaseDescription = ((InventoryItem)objItemResult.recordList[0]).purchaseDescription; objInventoryItem.binNumberList = new InventoryItemBinNumberList(); objInventoryItem.binNumberList.binNumber = objItemBinNumbers; objInventoryItem.binNumberList.replaceAll = false; //Request to update item with bins WriteResponse objWriteResponse = service.update(objInventoryItem); if (objWriteResponse.status.isSuccess != true) { Console.WriteLine(objWriteResponse.status.statusDetail[0].message); return objWriteResponse.status.statusDetail[0].message; } Console.WriteLine("Bins successfully updated for: "+((InventoryItem)objItemResult.recordList[0]).itemId); return "Bins successfully updated for: " + ((InventoryItem)objItemResult.recordList[0]).itemId; } return string.Empty; }