Saturday, May 4, 2019

C# > Performing the getItemAvailability operation with a list of Item Internal ID's

Below is a sample code of how to perform the getItemAvailability operation with a List of Item Internal ID's. Please note a valid login session is required. You must also have existing Items in your account.

if (sr.status.isSuccess)
{
  //Assigning the Search Results ID's to the to a List of Strings
  SearchRow[] sr1 = (SearchRow[])sr.searchRowList;
  List<string> ids = new List<string>();
  foreach (var searchRow in sr1)
  {
   var searchRs = (ItemSearchRow)searchRow;
   SearchColumnSelectField[] scsf2 = searchRs.basic.internalId;
   ids.Add(scsf2[0].searchValue.internalId);
  }

  //Creating the ItemAvailablityFilter Object.
  ItemAvailabilityFilter iaf = new ItemAvailabilityFilter();

  // Creating an Array of type RecordRef
  RecordRef[] rfa = new RecordRef[ids.Count];

  // Looping through the List of Strings and Assigning the internal Id's of the Records.
  for(int i = 0; i<ids.Count; i++){
   RecordRef rfa1 = new RecordRef();
   rfa1.internalId = ids[i];
   rfa1.type = RecordType.inventoryItem;
   rfa[i] = rfa1;

  }
  //Assigning the array of RecordRef's to the ItemAvailabilityFilter Object.
  iaf.item = rfa;

 // Performing the getItemAvailability operation.
 GetItemAvailabilityResult giar = nss.getItemAvailability(iaf);
 if (giar.status.isSuccess == true)
 {
  Console.Write("Item Availability Operation Successful");
  Console.Read();
 }
}

No comments:

Post a Comment