Help With Adapter multi whereClauses

I should know this but I’m having a bit of trouble with calling a getRows method on the PO adapter.
I am passing in the PO Num, PO Line, and PO Rel Num to return a single PO Release record field.
My code is below:

private void oTrans_receiptAdapter_AfterAdapterMethod(object sender, AfterAdapterMethodArgs args)
{
	// ** Argument Properties and Uses **
	// ** args.MethodName **
	// ** Add Event Handler Code **

	// ** Use MessageBox to find adapter method name
	// EpiMessageBox.Show(args.MethodName)
	switch (args.MethodName)
	{
		case "GetDtlPOLineInfo":
			//set rvcDtl.LotNum field from adapter method. This stopped working via BPM after the update to 10.2 in June 2018, so I'm tring a custom approach
			int poNum = (int)edvRcvDtl.dataView[edvRcvDtl.Row]["PONum"];
			int poLine = (int)edvRcvDtl.dataView[edvRcvDtl.Row]["POLine"];
			//int poRelNum = (int)edvRcvDtl.dataView[edvRcvDtl.Row]["PORelNum"];
			int poRelNum = 1;
			try
			{
				//edvRcvDtl.dataView[edvRcvDtl.Row]["LotNum"] = ReturnLotFromAdapter(poNum, poLine, poRelNum);
				MessageBox.Show((string)ReturnLotFromAdapter(poNum, poLine, poRelNum));
			}	
			catch(Exception ex)
			{
				MessageBox.Show(ex.Message.ToString());
			}
			//MessageBox.Show(poNum.ToString() + poLine.ToString() + poRelNum.ToString());
			break;
	}

}

private string ReturnLotFromAdapter(int poNum, int poLine, int poRelNum)
{
	string lot = null;
	//use the adapter to return the lot num from the first release of the PO 
	using(POAdapter adapterPO = new POAdapter(oTrans))
	{
		adapterPO.BOConnect();
		Ice.Lib.Searches.SearchOptions opts = new SearchOptions(SearchMode.AutoSearch);		
		opts.DataSetMode = DataSetMode.RowsDataSet;

		string whereClausePOHeader = "PONum = poNum";
		string whereClausePODtl ="POLine = poLine";
		string whereClausePORel = "PORelNum = poRelNum";
		opts.NamedSearch.WhereClauses.Add("POHeader", whereClausePOHeader);		
		opts.NamedSearch.WhereClauses.Add("PODetail", whereClausePODtl);	
		opts.NamedSearch.WhereClauses.Add("PORel", whereClausePORel);	
		bool more; 			
		var dsPO = (Erp.BO.PODataSet)adapterPO.GetRows(opts, out more);
		if(dsPO!=null)
		{
			//get the lot
			//lot = (string)adapterPO.POData.PORel[0]["LotNum_c"];
			lot = (string)dsPO.PORel[0]["LotNum_c"];
		}			

		adapterPO.Dispose();
	}
	return lot;
}

I’ve verifed in the BL tester that this is indeed a good way to return the single row I am looking for from the dataset, but I get this exception when I run the code:

image

I am at a loss as to why this might be happening, any ideas are appreciated, thanks!

Leave the POHeader and PODetail whereClauses empty and only add one for PORel and pass in all the conditios there
PONum = and POLine= and PORel= see if it helps

When I try that in both the BL tester and the code I wrote, it simply freezes up…hmm

Its returning too much stuff… why don’t you try to use the POrelSearch adapter instead
Erp.Adapters.PORelSearch

1 Like

Blazing fast in the BL tester, but still freezes up the UI in the form. I’ll play around with it a bit and mark this one solved once I get it working, thanks man

Here’s the working code using the PORelSearch adapter

private string ReturnLotFromAdapter(int poNum, int poLine, int poRelNum)
	{
		string lot = null;
		//use the adapter to return the lot num from the first release of the PO 
		using(PORelSearchAdapter adapterPO = new PORelSearchAdapter(oTrans))
		{
			adapterPO.BOConnect();
				
			bool recs = adapterPO.GetByID(poNum, poLine, poRelNum);
			if(recs)
			{
				lot = (string)adapterPO.PORelSearchData.PORel[0]["LotNum_c"];
			}
			adapterPO.Dispose();
		}
		return lot;
	}

Thanks Jose!

1 Like