Best Adapter/Search Method to get Default Warehouse given Plant ID

I have a company and a plant and I need to get the default warehouse for that plant. What Method or adapter can I use to get this? I’ve already tried this…

	private string GetSiteDefaultWhse(string sSite, string sCompany)
	{
	
		// Wizard Generated Search Method
		// You will need to call this method from another method in custom code
		// For example, [Form]_Load or [Button]_Click

		bool recSelected;
		string whereClause = string.Format("Company = '{0}' AND Plant = '{1}'", sCompany, sSite);
		System.Data.DataSet dsPlantConfCtrlAdapter = Ice.UI.FormFunctions.SearchFunctions.listLookup(this.oTrans, "PlantConfCtrlAdapter", out recSelected, false, whereClause);

		//we found a record
		if (recSelected)
		{
			System.Data.DataRow adapterRow = dsPlantConfCtrlAdapter.Tables[0].Rows[0];
			return String.Empty;
		}

		return String.Empty;
	
	}

If I remember there is a “PlantConfCtrl” or so Adapter and then you can search by Plant and read the DefaultWhse Column.

That’s the one I’m using up above

Then just try

return adapterRow["DefaultWhse"].ToString();

you should have the Default Whse then

1 Like

It was just weird not seeing that property being returned within the dataset?

Depending on the BO GetList () (List Lookup) may not return all the fields you may have to switch to a RowsDataSet.

2 Likes

image

You have to put it in here

//we found a record
		if (recSelected)
		{
			System.Data.DataRow adapterRow = dsPlantConfCtrlAdapter.Tables[0].Rows[0];
			**return adapterRow["DefaultWhse"].ToString();**
		}

		return String.Empty;

adapterRow is defined in the if statement #Scope

As I suspected…

I’ll keep looking for methods to get what I want!!! Linq query would be nice

You need to switch to a RowsDataSet GetList() doesn’t include all the columns.
Here’s an example (not using the same adpter) but the syntax is what you need

 string whereClause = "Key1 = '" + key1 + "'";
            System.Collections.Hashtable whereClauses = new System.Collections.Hashtable(1);
            whereClauses.Add("UD100", whereClause);
 
            // Call the adapter search.
            SearchOptions searchOptions = SearchOptions.CreateRuntimeSearch(whereClauses, DataSetMode.RowsDataSet);
            this._ud100Adapter.InvokeSearch(searchOptions);
 if ((this._ud100Adapter.UD100Data.UD100.Rows.Count > 0))
            {
                this._edvUD100.Row = 0;
                this._edvUD100A.Row=0;
            } else
            {
                this._edvUD100.Row = -1;
                this._edvUD100A.Row=-1;
            }
1 Like

Yeah so the listLookup gets the most essential columns. Rows lookup gets you all of them. You could switch to what Jose gave you it will work, another option is to use GetRows Method.

2 Likes

You can also use our old friend the BOReader

1 Like

@hasokeric

I just ended up doing this! Thanks for the help.

	private string GetSiteDefaultWhse(string sSite, string sCompany)
	{
		try 
		{ 
			// Declare and Initialize EpiDataView Variables
 			// Declare and create an instance of the Adapter. 
			PlantConfCtrlAdapter adapterPlantConfCtrl = new PlantConfCtrlAdapter(this.oTrans); 
			adapterPlantConfCtrl.BOConnect(); 

			Ice.Lib.Searches.SearchOptions opts = new SearchOptions(SearchMode.AutoSearch); 
			opts.DataSetMode = DataSetMode.RowsDataSet; 

			string whereClause = string.Format("Company = '{0}' AND Plant = '{1}'", sCompany, sSite);
			opts.NamedSearch.WhereClauses.Add("PlantConfCtrl",whereClause);

			//The first parameter is the Table name in the BO that will filter 
			System.Boolean morePages = false;

			// Call Adapter method 
			System.Data.DataSet dsPlantConfCtrl = adapterPlantConfCtrl.GetRows(opts, out morePages); // Cleanup Adapter Reference

			string defWhse = dsPlantConfCtrl.Tables[0].Rows[0]["DefaultWhse"];

			adapterPlantConfCtrl.Dispose(); 

	   		return defWhse;
	  	}
	   catch (System.Exception ex) 
	   { 
		   ExceptionBox.Show(ex); 
	   } 
	   
	   return string.Empty;
	}
1 Like