Not a single item

I’m trying to retrieve a value from a legacy database using federation. Here is what I’ve done: 1. Added a new field in “Part” ItemType “and named it “min_total_stock” with type “Federation” 2. Added field “min_total_stock” to Part FORM 3. Created a new method “MIN_Calculate_Total_Stock1” – see below 4. Added METHOD “MIN_Calculate_Total_Stock1” to “Part” ItemType within “Server Events” tab with event “onAfterGet” When filtering Parts for a single record, it works fine (a value for “min_total_stock” shows in form, but if many records are return in the grid I get an error message “Not a single item” Any help would be appreciated Thanks //==MIN_Calculate_Total_Stock1===// string masterpart = this.getProperty("item_number"); System.Data.OleDb.OleDbConnection myConnection = new System.Data.OleDb.OleDbConnection(@"Provider=SQLOLEDB;Data Source=000.00.000.0; Initial Catalog=WaspTrackInventory; User ID=admin;Password=Pass;"); string SQL = "select item_number,xqty from WaspTrackInventory.dbo.xArasPartQtySum where item_number = '" + masterpart + "';"; System.Data.OleDb.OleDbCommand com = new System.Data.OleDb.OleDbCommand(SQL); com.Connection = myConnection; myConnection.Open(); System.Data.OleDb.OleDbDataReader myDataReader = com.ExecuteReader(); if (myDataReader.HasRows != true) { this.setProperty("min_total_stock","None"); } else while (myDataReader.Read()) { this.setProperty("min_total_stock",myDataReader.GetString(1)); } myConnection.Close(); return this;
Parents
  • Hello, I believe the issue you're running into is that the context item from onAfterGet server event is the collection of items returned from the get query. The not a single item error is being thrown on string masterpart = this.getProperty("item_number"); because the getProperty function cannot be called on a collection. The simplest way to work around this issue would be to wrap the bulk of your code in a for loop and call it for each individual item in the collection like so.
    for (int i = 0, length = this.getItemCount(); i < length; i++)
    {
    Item currItem = this.getItemByIndex(i); // Select one item at a
    string masterpart = currItem.getProperty("item_number");
    // Put the rest of your code in this loop too
    }
    Chris
    Christopher Gillis Aras Labs Software Engineer
Reply
  • Hello, I believe the issue you're running into is that the context item from onAfterGet server event is the collection of items returned from the get query. The not a single item error is being thrown on string masterpart = this.getProperty("item_number"); because the getProperty function cannot be called on a collection. The simplest way to work around this issue would be to wrap the bulk of your code in a for loop and call it for each individual item in the collection like so.
    for (int i = 0, length = this.getItemCount(); i < length; i++)
    {
    Item currItem = this.getItemByIndex(i); // Select one item at a
    string masterpart = currItem.getProperty("item_number");
    // Put the rest of your code in this loop too
    }
    Chris
    Christopher Gillis Aras Labs Software Engineer
Children
No Data