Need Assistance Troubleshooting Custom Quick Search Criteria

Hello.

My objective is to use the screen customization code provided by @josecgomez for passing a value directly into a Quick Search’s criteria. At this point, all code compiles with no errors, so I’m fairly certain that I have simply misinterpreted how to swap the example code’s configuration (ABCCodes) to my own, which is to ultimately replace the Ship To… search button on Sales Order Entry with my Quick Search. As you likely know, the base search does a great job of passing the customer number so only the order customer’s Ship To’s are shown.

Here’s the relevant info on my Quick Search:

  • QuickSearch: maCustShipTo_QS
  • BAQ: maCustShipToQS
  • Return Column: Customer_CustID
  • Criteria Column: Customer_CustID
  • Criteria Type: Constant
  • Criteria Value: blank

The custom button on the Order Entry screen is called btnShipToSearch, and calls the MouseEventHandler method which I called CustomShipToQuickSearch.

Here what I ended up with on the screen customization code:

extern alias Ice_Adapters_QuickSearch;
extern alias Ice_Contracts_BO_QuickSearch;
using Erp.UI;
...
this.btnShipToSearch.MouseClick += new MouseEventHandler(this.CustomShipToQuickSearch);
this.btnShipToSearch.MouseClick -= new MouseEventHandler(this.CustomShipToQuickSearch);
...
private void CustomShipToQuickSearch(object sender, MouseEventArgs args)
{
	sender = oTrans.EpiBaseForm;
	QuickSearchAdapter _qdA = new QuickSearchAdapter(oTrans);
	_qdA.BOConnect();
	_qdA.GetByID("","maCustShipTo_QS");
	QuickSearchDataSet qsds = _qdA.QuickSearchData;
	EpiDataView OrderView = ((EpiDataView)(this.oTrans.EpiDataViews["OrderHed"]));
	string searchCustID = "";
	if(OrderView.dataView.Count > 0)
	{
		searchCustID = OrderView.dataView[0]["CustomerCustID"].ToString();
	}
	MessageBox.Show("searchCustID is " + searchCustID.ToString());
	//I have a criteria item in my Quick Search that I  need to pass dynamically.
	//so I look through all the criteria items until I find mine and I replace
	//the CriteriaValue with the value I want to filter on.
	foreach(QuickSearchDataSet.QuickSearchCriteriaRow r in qsds.QuickSearchCriteria)
	{
	    if(r.FieldName.Equals("Customer_CustID") && r.CriteriaType.Equals("Constant"))
	    {
	        r.CriteriaValue = searchCustID;
			MessageBox.Show("Criteria set");
	        break;
	    }
	}
	 
	try
	{
	    using(QuickSearchPanel panel = _qdA.GetQuickSearchPanel(oTrans.EpiBaseForm))
	    {
	        if(panel !=null)
	        {
	            using(QuickSearchForm form = new QuickSearchForm(_qdA))
	            {
	                form.LastQS = "maCustShipTo_QS";
	                System.Reflection.MethodInfo mi = form.GetType().GetMethod("addQuickSearchPanel",System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
	                mi.Invoke(form, new object[]{panel});
	 
	                SearchOptions options = SearchOptions.CreateSearchForm(DataSetMode.ListDataSet);
	                options.Sender = sender;
	 
	                options.SelectMode = SelectMode.SingleSelect;
	                form.ShowDialog(new Ice.Lib.Searches.EpiSearchEngine((EpiBaseAdapter)_qdA),options);
	                System.Reflection.FieldInfo fi = form.GetType().GetField("selectObject", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
	                object o= fi.GetValue(form);
	                if(o != null)
	                {
	                    // o is a String containing your returned key
	                    // if multi select o is an ArrayList containing all selected keys.
	                    if (o == null)
	                           return;
	                    SearchOptions opts = new SearchOptions(SearchMode.AutoSearch);
	                    opts.NamedSearch.WhereClauses.Add("Customer_CustID", string.Format("CustID='{0}'",o.ToString()));
	                    opts.DataSetMode = DataSetMode.RowsDataSet;
	                    SalesOrderAdapter _adapter = (SalesOrderAdapter)csm.TransAdaptersHT["oTrans_adapter"];
	                    _adapter.ClearData();
	                    _adapter.InvokeSearch(opts);
	                    oTrans.NotifyAll();
	                    EpiDataView edvA = oTrans.Factory("Customer_CustID");
	                    edvA.Row=0;
	                    edvA.Notify(new EpiNotifyArgs(oTrans, 0, EpiTransaction.NotifyType.Initialize));
	                }
	            }
	        }
	    }
	}
	catch(Exception ex)
	{
		ShowExceptMsg("Exception processing Quick Search: ", ex.Message, "CustomShipToQuickSearch");
	}
}

Current State: When the custom button is clicked, the QuickSearch is invoked, but the search results are for all customers, not just the one on the order. I do see the MessageBox stating “searchCustID is 100”, but not the second one (“Criteria Set”), so I may have some code in the foreach that is wrong.

If anyone can take a look and help me to figure out what I may have overlooked, that would be great.
Thanks, Tony G.