Form Event Wizard - Adapter

I need to hide a custom checkbox on Receipt based on a condition of the PO Detail.

I can make the Form Event Wizard start the process for AfterFieldChange of the RcvHead: PONum field.

private void RcvHead_AfterFieldChange(object sender, DataColumnChangeEventArgs args)
	{
		// ** Argument Properties and Uses **
		// args.Row["FieldName"]
		// args.Column, args.ProposedValue, args.Row
		// Add Event Handler Code
		switch (args.Column.ColumnName)
		{
			case "PONum":
				break;
		}
	}

I know that I have to use the PONum to get to the PODetails table. I want to use the BTOOrder column to test if I want the checkbox hidden or not.
When I would code in a BPM, I would reference the db directly to get my data. But I’ve been reading on here that I should use an adapter, as this will all be client side. I’m having trouble finding an example of calling the adapter in the manuals in this context - the form I’m on (receipt) is not directly related to the table I need (PODetail). And I’ve never used an adapter before.

I’m also reading that I should not set the controls of the checkbox using “csm.GetNativeControlReference” like I would expect. Instead I should use the EpiDataview .ExtendedProperties[“IsHidden”]
Can someone confirm this?

And the other question is: Does someone have a good example of the adapter like I’m trying to do?
The Custom Object Explorer show me this:

using Erp.Adapters;

POAdapter [varAdapterName]  = new POAdapter([UIForm]);
[varAdapterName].BOConnect();

// Get Property
PODetailDataTable [varName] = [varAdapterName].POData.PODetail;

[varAdapterName].Dispose();

I feel like I’m supposed to fill inside the brackets of new POAdapter([UIForm]); and replace UIFORM. But I’m not sure with what.
Help please.

Admittedly I didnt read the whole post, but couldnt you just use a RowRule for this?

That’s okay, I’m all over the place.

I read through the steps of that and tried to apply it. I feel that how I need to evaluate the PO Detail is not simple enough.
I can choose “CustomCondition” for the Rule Condition and assume that I can evaluate on the POdetail. But the Rule Value is just showing a list of Constant that don’t seem to apply.

If you are just getting information, you can also use the dynamic query adapter to run a BAQ and get the information that you want. The full adapters like PO are more useful when you are trying to manipulate data because they handle the whole dataset for you. But I don’t think you need the whole dataset for this case.

Check out the thread below for how to call a query in code. Basically, you’ll make a BAQ that runs on parameters to get the information that you want, then you can call that query in code, then you use the results to set the visibility of your control.

1 Like

This is good because the best way for me to evaluate my PODetail field is through aggregate. The BAQ does this nicely without C# code.
I’ll hammer on this route tomorrow.
Thanks!

1 Like

Ah see your dilemma. You want to use a condition from a view (PODtl) that isnt on the form. Yeah, you could use custom condition and BOReader:

   Ice.Proxy.Lib.BOReaderImpl _bor = WCFServiceSupport.CreateImpl<Ice.Proxy.Lib.BOReaderImpl>((Ice.Core.Session)oTrans.Session, Epicor.ServiceModel.Channels.ImplBase<Ice.Contracts.BOReaderSvcContract>.UriPath);
string whereClause = string.Format("PONum = {0} AND POLine =  {1} ",myPONum, myPOLine);
                DataSet ds = _bor.GetList("Erp:BO:PODetailSearch", whereClause, "MyField");  //namespace,whereclause,columns
var myField = ds.Tables[0].Rows[0]["MyField"];
if(myField == myCondition) return true;

This is a simplfied gist that would need some error handling etc.

Perhaps an even easier approach would be to create your own DataView (either BAQDataView or otherwise). You could have it driven off the selected RcvDtl record.

I would offer a Foreign Key View for POHeader and the a Sub Table View for PODetail. This would give you access to the field you need (no code).
Then a RowRule for hiding the checkbox.

Jason, I had considered the same, but I dont know that there is an easy way to get ReceiptLine -> PO ->PO Line using FVK is there?

Yup!


Nice! Then I definitely suggest this route!

Be aware that Foreign Key View uses GetByID method to get it’s data. In a context where there is not a lot of data returned it’s ok. But, in scenarios where it deals with Jobs (especially large jobs), the cost of getting a single value using FKV is TOTALLY to be avoided…the cost is too high.

I’m working on this, now.
@Banderson 's way is the way I’m starting to try. Not to discount the input of the others. But I like working with the results of a BAQ for my aggregate result.
My BAQ gives me correct results with the input parameter.

So, I’m putting this into my Test environment:

	private void RcvHead_AfterFieldChange(object sender, DataColumnChangeEventArgs args)
	{
		// ** Argument Properties and Uses **
		// args.Row["FieldName"]
		// args.Column, args.ProposedValue, args.Row
		// Add Event Handler Code
		DynamicQueryAdapter ABTO = new DynamicQueryAdapter(oTrans);
		ABTO.BOConnect();
		QueryExecutionDataSet QEDS = ABTO.GetQueryExecutionParametersByID("ArrivedBTO");
		QEDS.ExecutionParameter.Clear();
		QEDS.ExecutionParameter.AddExecutionParameterRow("@PONum", "PONum" ,"int", false, Guid.Empty, "A");
		ABTO.ExecuteByID("PONum",QEDS);
		DataTable dt = ABTO.QueryResults.Tables["Results"];
		foreach (System.Data.DataRow r in ABTO.QueryResults.Tables["Results"].Rows)
		{
		MessageBox.Show(r["Calculated_BTO_Totes"].ToString());
		}
		switch (args.Column.ColumnName)
		{
			case "PONum":
				break;
		}
	}

The code compiles, but my messagebox never shows.

I’ve guessed as to what I should put here:

Any thoughts?

I’m assuming you tried a message box outside of the for loop to make sure the event was firing?

No, but that is smart…
facepalm


Did NOT fire… hmmm

And, as far as your circled part, that should be coming from something on in your dataview, a variable of some sort. Right now, you are just passing in the string “PONum” as your parameter. I’m guess you want to pass in the actual Po Number that is in the dataview. Right?

Side note, have you tried the extension that Jose made for visual studio code, or Visual studio? It’s worth the work to get it set up, because there are a lot of shortcuts that make this type of development go much much faster and less frustrating.

I’ve read about that this week, but have not tried to make the connection. This landed in my lap instead.

MessageBox outside the loop did not fire:

I think you have your code in the wrong place. If you go back to the original code that the wizard put in you should have that switch statement in there, and your code needs to go in that.

The first code block I posted show this code added just before the switch.

It needs to be after the case, before the break.