BAQ Dataview linked to unbound controls?

I am currently using the code below to define my BAQDataViews which populated my grids. I want to use a parameter-driven BAQ instead.

public void SetupECODV()
    // Creates the view into EcoRev (BAQ = getPartRevOpECO)
	{
		dtEcoRevOps = new DataTable(); //instantiate DT

		var colMyPart = new DataColumn("Part"); // inst column
		colMyPart.ExtendedProperties["Like"]="Part.PartNum";	//add like for right click open with
		dtEcoRevOps.Columns.Add(colMyPart); // add custom column to DT (repeat for all columns)

		var colMyRev = new DataColumn("Rev"); // inst column
		dtEcoRevOps.Columns.Add(colMyRev); // add custom column to DT (repeat for all columns)

		dtEcoRevOps.Columns.Add(new DataColumn("SysRowId",typeof(Guid))); // add guid column to DT (required)

		var dr = dtEcoRevOps.NewRow(); //inst a new row
		dr["SysRowId"] = Guid.NewGuid(); // just set the guid for the new row
		dtEcoRevOps.Rows.Add(dr); // add the row to the DT to enable fields in the table

		dvEcoRevOps = new EpiDataView(); //inst the EDV
		dvEcoRevOps.dataView = dtEcoRevOps.DefaultView; // set the EDV to the default view of the DT created above (default view is unfiltered view of entire DT)
		oTrans.Add("OpsList",dvEcoRevOps); // adds the EDV to the binding list

		bdvEco = new BAQDataView("getPartRevOpECO"); //inst the BDV
		oTrans.Add("EcoRevOps",bdvEco); //add the BDV to the binding list (this is an unfiltered BDV. Filter the BDV with Pub/Sub)

		var fromPubPart= "OpsList.Part"; //whenever the listed field changes publish the new value
		oTrans.PublishColumnChange(fromPubPart,"FromPubPart"); //publish the value to otrans
		var fromPub = oTrans.GetPublisher(fromPubPart); //this pulisher 'fromPub' gets the notification when above field changes.
		bdvEco.SubscribeToPublisher(fromPub.PublishName,"ECORev_PartNum"); // subscribe BDV to fromPub created above. filer by listed field based on publisher.

		var fromPubRev= "OpsList.Rev"; //whenever the listed field changes publish the new value
		oTrans.PublishColumnChange(fromPubRev,"FromPubRev"); //publish the value to otrans
		var fromPub2 = oTrans.GetPublisher(fromPubRev); //this pulisher 'fromPub' gets the notification when above field changes.
		bdvEco.SubscribeToPublisher(fromPub2.PublishName,"ECORev_RevisionNum"); // subscribe BDV to fromPub created above. filer by listed field based on publisher.
	}

	public void SetupPartDV()
    // creates the view into PartRev (BAQ = EditAnyOp)
	{
		dtPartRevOps = new DataTable(); //instantiate DT

		var colMyPart = new DataColumn("Part"); // inst column
		colMyPart.ExtendedProperties["Like"]="Part.PartNum";	//add like for right click open with
		dtPartRevOps.Columns.Add(colMyPart); // add custom column to DT (repeat for all columns)

		var colMyRev = new DataColumn("Rev"); // inst column
		dtPartRevOps.Columns.Add(colMyRev); // add custom column to DT (repeat for all columns)

		dtPartRevOps.Columns.Add(new DataColumn("SysRowId",typeof(Guid))); // add guid column to DT (required)

		var dr = dtPartRevOps.NewRow(); //inst a new row
		dr["SysRowId"] = Guid.NewGuid(); // just set the guid for the new row
		dtPartRevOps.Rows.Add(dr); // add the row to the DT to enable fields in the table

		dvPartRevOps = new EpiDataView(); //inst the EDV
		dvPartRevOps.dataView = dtPartRevOps.DefaultView; // set the EDV to the default view of the DT created above (default view is unfiltered view of entire DT)
		oTrans.Add("OpsList1",dvPartRevOps); // adds the EDV to the binding list

		bdvPart = new BAQDataView("EditAnyOp"); //inst the BDV
		oTrans.Add("PartRevOps",bdvPart); //add the BDV to the binding list (this is an unfiltered BDV. Filter the BDV with Pub/Sub)

		var fromPubPart1= "OpsList1.Part"; //whenever the listed field changes publish the new value
		oTrans.PublishColumnChange(fromPubPart1,"FromPubPart1"); //publish the value to otrans
		var fromPub1a = oTrans.GetPublisher(fromPubPart1); //this pulisher 'fromPub' gets the notification when above field changes.
		bdvPart.SubscribeToPublisher(fromPub1a.PublishName,"PartRev_PartNum"); // subscribe BDV to fromPub created above. filer by listed field based on publisher.

		var fromPubRev1= "OpsList1.Rev"; //whenever the listed field changes publish the new value
		oTrans.PublishColumnChange(fromPubRev1,"FromPubRev1"); //publish the value to otrans
		var fromPub2a = oTrans.GetPublisher(fromPubRev1); //this pulisher 'fromPub' gets the notification when above field changes.
		bdvPart.SubscribeToPublisher(fromPub2a.PublishName,"PartRev_RevisionNum"); // subscribe BDV to fromPub created above. filer by listed field based on publisher.
	}

Once I setup my grids, I would like to filter the underlying BAQ to return results faster. With the method above, the BAQ pulls all parts and revs, then just displays the ones that match your criteria. I would rather put the parameter back into the BAQ and run the BAQ only on the part/rev that I need. I have mashed together some code below that I think will do this, but I am not sure how to integrate it with the code I am using above. I think I need to get rid of the pub/sub lines for each BAQDV. Then I need to somehow assign the results of the code below to the BAQDVs. Right?

private void New_FilterBAQDataView(BAQDataView iBaqView, string BAQ, string thisPart, string thisRev)
{
DynamicQueryAdapter dqa = new DynamicQueryAdapter(oTrans);
dqa.BOConnect();		
QueryExecutionDataSet qeds = dqa.GetQueryExecutionParametersByID(BAQ);
qeds.ExecutionParameter.Clear();
qeds.ExecutionParameter.AddExecutionParameterRow("part", thisPart, "nvarchar", false, Guid.NewGuid(), "A");
qeds.ExecutionParameter.AddExecutionParameterRow("rev", thisRev, "nvarchar", false, Guid.NewGuid(), "A");
dqa.ExecuteByID(BAQ, qeds);
if (dqa.QueryResults.Tables["Results"].Rows.Count > 0)
{
// apply the results of the BAQ to the BAQDV (and underlying grid)
//iBaqView.Source = dqa.QueryResults; //this pseudo code doesnt work...
}
}

EDIT: I forgot to add, that I am currently applying a filter to my BAQDVs like this:

		FilterBAQDataView(bdvEco,  "ECORev_PartNum = '"  + txtPartNum.Text + "' AND ECORev_RevisionNum = '" +  cmbRevNum.Text + "'");
		FilterBAQDataView(bdvPart, "PartRev_PartNum = '" + txtPartNum.Text + "' AND PartRev_RevisionNum = '" + cmbRevNum.Text + "'");

And here is the code for that function:

	private void FilterBAQDataView(BAQDataView iBaqView, string iWhereClause)
	{
	    iBaqView.AdditionalFilter = iWhereClause;
	    iBaqView.dataView.RowFilter = iWhereClause;
	    iBaqView.Notify(new EpiNotifyArgs(oTrans, 0, EpiTransaction.NotifyType.Initialize));
		//not sure if code below is needed...
		MethodInfo mi = iBaqView.GetType().GetMethod("InvokeExecute", BindingFlags.Instance | BindingFlags.NonPublic);
		mi.Invoke(iBaqView, new object[]{ true });
	}

I want to replace the above filtering, with my ā€œnewā€ parameter filtering at the BAQ level.
Thank you for your time!
Nate

Why parameters instead? What version of Epicor are you on? in 600+ you can pass paramters in the BAQDataView.

I am on 700. I figured that parameters would filter my BAQ before running it and returning every single part/rev.

BAQDataView Pub /Sub does that too. It adds a whereClause to your BAQ on the fly.

Ahhh! I think I see what is going on. I create my BAQDVs, and they are not filtered until I run that extra function to actually apply the where clause. Does this make sense? Are my BAQDVs being populated with unfiltered data until I run the filter BAQ function? Is there a way around this? So My BAQ DVs donā€™t get loaded until I have some filter criteria? There may still be something else going on here slowing things down.

You renā€™t using Pub Sub? If you setup the pub sub it should add the filter automatically

Yes, I am currently using pub/sub as I outlined above. It does work, but seems like the BAQ is running longer than it should if it was filtered on just the part/rev.

Are you adding the pub / sub at the beginning when you intialize the BAQ Data View?

I setup my BAQDVs right at the start.

	public void InitializeCustomCode()
	{
		SetupECODV();
		SetupPartDV();

But at this time, I donā€™t have part and rev yet. Once the user enters part and rev in the text boxes, (OnLeave rev text box), then the filters are applied to the BAQ DVs:

private void CheckForCheckedOut()
	{
		oTrans.PushStatusText("Looking for checked out part/revs...", false);
		FilterBAQDataView(bdvEco,  "ECORev_PartNum = '"  + txtPartNum.Text + "' AND ECORev_RevisionNum = '" +  cmbRevNum.Text + "'");
		FilterBAQDataView(bdvPart, "PartRev_PartNum = '" + txtPartNum.Text + "' AND PartRev_RevisionNum = '" + cmbRevNum.Text + "'");

CheckForCheckedOut is triggered when user leaves the rev control and the part and rev both have values.

It shouldnā€™t apply Filters to the BAQ. If you are using Pub Sub the Filter happens automatically Iā€™m not following what the point of the filters are.
Iā€™m a little lost

The process should be

Add BAQDataView
Register Pub / Sub Meaning register which fields in your other dataview will dynamically (and automatically filter the baq)

Tie BAQ to a Gridā€¦ what the magic happen

If I donā€™t use the FilterBAQDV function, then my grids both contain an unfiltered list of parts/revs.
Following your process, I think I have:
Added the BAQDVs with my SetupECODV() and SetupPartDV() functions.
Inside these functions, I also publish and subscribe to the fields I am interested in.
Finally, after I created the DVs and saved and closed and reopened, only then can I assign the DVs to my grids with the EpiBinding property.

If I just do these steps, my grids both contain all parts/revs, not just the ones that match my user controls. So I figured out how to add the filter to my BAQDVs with the FilterBAQDataView function. Once I ran this function (after looking at the user supplied part and rev), then my grids are properly showing only the filtered BAQ results for that part/rev.

Iā€™m waiting for the magic to happenā€¦
:slight_smile:

Are your user controls tied to a DataView?

Not my part and rev. We went over this many times. I canā€™t enter values into an epibound field. as soon as I set an epibinding the field is read-only. So I have two unbound controls for part/rev that the user can enter data into.

Ok you create a custom data view named ā€œOpsListā€ and you are binding your textboxes to OpsLsit.part and OpsList.Rev? and it goes readonly?

If thatā€™s the case right after you create your data view simply set the ReadOnly property to false on those two fields and set the KeyField property to true in the control.

dtEcoRevOps.Columns["Part"].ExtendedProperties["ReadOnly"] = false;
dtEcoRevOps.Columns["Rev"].ExtendedProperties["ReadOnly"] = false;

image

I just tried again, and the control did not go read-only! Wooo!!! However, I need to bind the part number and rev to both OpsList, and OpsList1, depending on which BAQDV we are using. In my experience I canā€™t change the epibinding of a control at runtime.

Just pub sub both of BAQDataViews to the same OpsList there shouldnā€™t be anything stopping you from doing that.
Is just a field it can be used for both filters.

Then any changes to Part / Rev on OpsList will trigger the Two BAQDataViews to re-run / filter.

I am missing something here. Right now I setup two BAQDVs. One is based on the PartRev table (OpsList1), and one is based on the EcoRev table (OpsList). Can you look at my SetupDV functions and let me know what I did wrong? I have see four DVs listed in my epibindings. OpsList, OpsList1, PartRevOps, and EcoRevOps. My grids are bound to PartRevOps and EcoRevOps.

Iā€™m so confused!

LoL see the diagram above. You are filtering the BAQDataViews (both of them) by Part / Rev Right?

So thereā€™s no reason to have two different Publishers. You create 1 EpiDataView call it OpsList then subscribe both the BAQDataViews to that single DataView

So your code could look like thisā€™

public void SetupBAQDvs()
	{
		//Create a EpiDataView to use for filtering
		dtEcoRevOps = new DataTable(); //instantiate DT
		var colMyPart = new DataColumn("Part"); // inst column
		colMyPart.ExtendedProperties["Like"]="Part.PartNum";	//add like for right click open with
		dtEcoRevOps.Columns.Add(colMyPart); // add custom column to DT (repeat for all columns)

		var colMyRev = new DataColumn("Rev"); // inst column
		dtEcoRevOps.Columns.Add(colMyRev); // add custom column to DT (repeat for all columns)

		dtEcoRevOps.Columns.Add(new DataColumn("SysRowId",typeof(Guid))); // add guid column to DT (required)

		var dr = dtEcoRevOps.NewRow(); //inst a new row
		dr["SysRowId"] = Guid.NewGuid(); // just set the guid for the new row
		dtEcoRevOps.Rows.Add(dr); // add the row to the DT to enable fields in the table

		dvEcoRevOps = new EpiDataView(); //inst the EDV
		dvEcoRevOps.dataView = dtEcoRevOps.DefaultView; // set the EDV to the default view of the DT created above (default view is unfiltered view of entire DT)
		oTrans.Add("OpsList",dvEcoRevOps); // adds the EDV to the binding list

		
		
		//Publish Changes to Part and Rev columns
		var fromPubPart= "OpsList.Part"; //whenever the listed field changes publish the new value
		oTrans.PublishColumnChange(fromPubPart,"FromPubPart"); //publish the value to otrans
		var fromPub = oTrans.GetPublisher(fromPubPart); //this pulisher 'fromPub' gets the notification when above field changes.
		

		var fromPubRev= "OpsList.Rev"; //whenever the listed field changes publish the new value
		oTrans.PublishColumnChange(fromPubRev,"FromPubRev"); //publish the value to otrans
		var fromPub2 = oTrans.GetPublisher(fromPubRev); //this pulisher 'fromPub' gets the notification when above field changes.
		
		
		
		//Setup the first BAQDataView
		bdvEco = new BAQDataView("getPartRevOpECO"); //inst the BDV
		oTrans.Add("EcoRevOps",bdvEco); //add the BDV to the binding list (this is an unfiltered BDV. Filter the BDV with Pub/Sub)
		bdvEco.SubscribeToPublisher(fromPub2.PublishName,"ECORev_RevisionNum"); // subscribe BDV to fromPub created above. filer by listed field based on publisher.
		bdvEco.SubscribeToPublisher(fromPub.PublishName,"ECORev_PartNum"); // subscribe BDV to fromPub created above. filer by listed field based on publisher.
		
		//Setup the Second BAQDataView
		bdvPart = new BAQDataView("EditAnyOp"); //inst the BDV

		oTrans.Add("PartRevOps",bdvPart); //add the BDV to the binding list (this is an unfiltered BDV. Filter the BDV with Pub/Sub)
		bdvPart.SubscribeToPublisher(fromPub.PublishName,"PartRev_PartNum"); // subscribe BDV to fromPub created above. filer by listed field based on publisher.
		bdvPart.SubscribeToPublisher(fromPub2.PublishName,"PartRev_RevisionNum"); // subscribe BDV to fromPub created above. filer by listed field based on publisher.
		
		
	}
1 Like