[SOLVED] Automatically select first list item in baqCombo field

My AP team wants to have the Part Class displayed on the AP Invoice Entry → Lines → Detail section.

Part/PartClass is not available in the EpiBinding dropdown so I created a BAQ and baqCombo that is filtered by Part.PartNum:

-- BAQ ID: GI-APInvPartClass
select top (1)  
	[Part].[Company] as [Part_Company],
	[Part].[PartNum] as [Part_PartNum],
	[PartClass].[ClassID] as [PartClass_ClassID],
	[PartClass].[Description] as [PartClass_Description]
from Erp.Part as Part
inner join Erp.PartClass as PartClass on 
	Part.Company = PartClass.Company
	and Part.ClassID = PartClass.ClassID
where (Part.PartNum = '[Like:Part.PartNum]')

Screenshot of customization dialog:

This works as far as getting the correct PartClass description in the dropdown, but I would like the dropdown to automatically select the list item.

image

use a BAQDataView to bind the combo to the BAQData and it will automatically show up in the dropdown.

3 Likes

Thanks for the response, Jose.

I watched the BAQ Dataview Example Video and came up with this code:

public void CreatePartClassBAQDV()
{
	// Pass the name of the BAQ to BAQDataView()
	PartClassBAQDV = new BAQDataView("GI-APInvPartClass");
	// Add the DataView to the list of bindings
	oTrans.Add("PartClassBAQDV", PartClassBAQDV);
	// Item on the existing form used to connect the BAQ
	string pub1Binding = "APInvDtl.PartNum"; // "APInvDtl.POPartNum" "Part.PartNum"
	IPublisher pub1 = oTrans.GetPublisher(pub1Binding);
	if (pub1 == null) 
	{
		// Generate a random name for the Publisher
		string pubName = Guid.NewGuid().ToString();
		oTrans.PublishColumnChange(pub1Binding, pubName);
		pub1 = oTrans.GetPublisher(pub1Binding);
	}
	if (pub1 != null)
		// Field in the BAQ to subscribe to
		PartClassBAQDV.SubscribeToPublisher(pub1.PublishName, "Part_PartNum");	
}

string currentPart = "0";
private void edvAPInvDtl_EpiViewNotification(EpiDataView view, EpiNotifyArgs args)
{
	// ** Argument Properties and Uses **
	// view.dataView[args.Row]["FieldName"]
	// args.Row, args.Column, args.Sender, args.NotifyType
	// NotifyType.Initialize, NotifyType.AddRow, NotifyType.DeleteRow, NotifyType.InitLastView, NotifyType.InitAndResetTreeNodes
	if ((args.NotifyType == EpiTransaction.NotifyType.Initialize))
	{
		if ((args.Row > -1))
		{
			if (currentPart != (string)view.dataView[args.Row]["PartNum"])
			{
				currentPart = (string)view.dataView[args.Row]["PartNum"];
				if (currentPart != "0")
				{
					MessageBox.Show(String.Format("Part_PartNum = '{0}'", currentPart));
					PartClassBAQDV.dataView.RowFilter = String.Format("Part_PartNum = '{0}'", currentPart);
				}
			}
			else
			{
				currentPart = "0";
			}
		}
	}
}

However, the epiUltraGrid does not populate any data. The MessageBox does show up every time I view a different line item, though.

You did run this function correct? CreatePartClassBAQDV()

1 Like

Which ultra grid? Ithought you had a combo box.

1 Like

@klincecum Yes, it’s at the top of the InitializeCustomCode() function.

@josecgomez I am using an ultra grid for now because that’s what was used in the BAQ Dataview Example Video.

Did you bind the grid to the new Data View?
Can you share your whole customization code.

1 Like
// **************************************************
// Custom code for APInvoiceForm
// Created: 6/28/2023 2:10:16 PM
// **************************************************

extern alias Erp_Contracts_BO_APInvoice;
extern alias Erp_Contracts_BO_APPromissoryNotes;
extern alias Erp_Contracts_BO_Company;
extern alias Erp_Contracts_BO_Part;
extern alias Erp_Contracts_BO_Vendor;
extern alias Erp_Contracts_BO_LogAPInv;
extern alias Erp_Contracts_BO_Project;
extern alias Erp_Contracts_BO_EmpBasic;
extern alias Erp_Contracts_BO_SupplierXRef;

using System;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Windows.Forms;
using Erp.Adapters;
using Erp.UI;
using Ice.Lib;
using Ice.Adapters;
using Ice.Lib.Customization;
using Ice.Lib.ExtendedProps;
using Ice.Lib.Framework;
using Ice.Lib.Searches;
using Ice.UI.FormFunctions;
using Ice.Lib.Broadcast;

public class Script
{
	// ** Wizard Insert Location - Do Not Remove 'Begin/End Wizard Added Module Level Variables' Comments! **
	// Begin Wizard Added Module Level Variables **

	private EpiDataView edvAPInvDtl;
	// End Wizard Added Module Level Variables **

	// Add Custom Module Level Variables Here **

	BAQDataView PartClassBAQDV;

	public void InitializeCustomCode()
	{
		CreatePartClassBAQDV();
		// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Variable Initialization' lines **
		// Begin Wizard Added Variable Initialization

		this.edvAPInvDtl = ((EpiDataView)(this.oTrans.EpiDataViews["APInvDtl"]));
		this.edvAPInvDtl.EpiViewNotification += new EpiViewNotification(this.edvAPInvDtl_EpiViewNotification);
		// End Wizard Added Variable Initialization

		// Begin Wizard Added Custom Method Calls

		// End Wizard Added Custom Method Calls
	}

	public void DestroyCustomCode()
	{
		// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Object Disposal' lines **
		// Begin Wizard Added Object Disposal

		this.edvAPInvDtl.EpiViewNotification -= new EpiViewNotification(this.edvAPInvDtl_EpiViewNotification);
		this.edvAPInvDtl = null;
		// End Wizard Added Object Disposal

		// Begin Custom Code Disposal

		// End Custom Code Disposal
	}

	public void CreatePartClassBAQDV()
	{
		PartClassBAQDV = new BAQDataView("GI-APInvPartClass");
        oTrans.Add("PartClassBAQDV", PartClassBAQDV);
        string pub1Binding = "APInvDtl.PartNum";
		// string pub1Binding = "APInvDtl.POPartNum";
		// string pub1Binding = "Part.PartNum";
        IPublisher pub1 = oTrans.GetPublisher(pub1Binding);
        if (pub1 == null) 
        {
            string pubName = Guid.NewGuid().ToString();
            oTrans.PublishColumnChange(pub1Binding, pubName);
            pub1 = oTrans.GetPublisher(pub1Binding);
        }
        if (pub1 != null)
            PartClassBAQDV.SubscribeToPublisher(pub1.PublishName, "Part_PartNum");	
	}

	string currentPart = "0";
	private void edvAPInvDtl_EpiViewNotification(EpiDataView view, EpiNotifyArgs args)
	{
		// ** Argument Properties and Uses **
		// view.dataView[args.Row]["FieldName"]
		// args.Row, args.Column, args.Sender, args.NotifyType
		// NotifyType.Initialize, NotifyType.AddRow, NotifyType.DeleteRow, NotifyType.InitLastView, NotifyType.InitAndResetTreeNodes
		if ((args.NotifyType == EpiTransaction.NotifyType.Initialize))
		{
			if ((args.Row > -1))
			{
				if (currentPart != (string)view.dataView[args.Row]["PartNum"])
				{
					currentPart = (string)view.dataView[args.Row]["PartNum"];
					if (currentPart != "0")
					{
						MessageBox.Show(String.Format("Part_PartNum = '{0}'", currentPart));
						PartClassBAQDV.dataView.RowFilter = String.Format("Part_PartNum = '{0}'", currentPart);
					}
				}
				else
				{
					currentPart = "0";
				}

				/*
				if (currentPart != "0")
				{
					MessageBox.Show(String.Format("Part_PartNum = '{0}'", currentPart));
					PartClassBAQDV.dataView.RowFilter = String.Format("Part_PartNum = '{0}'", currentPart);
				}
				*/
			}
		}
	}
}

It’s bound to PartClassBAQDV:

Your BAQ is using the Part table? Part_PartNum is a valid field in your BAQ? And you are hanging this on APInvoice Line and there’s a line… with a valid part?

1 Like

Here’s the BAQ:
image

I checked the APInvDtl table in SSMS:

image

And it looks like the trace shows the WHERE clause:

image

Okay so it is running are you sure that’s a valid part? In your part master

1 Like

I’m sure they are valid parts, otherwise the BAQ would not return any results:

image

oh wait don’t add that row filter. In initialize view I dind’t realize taht just remove everythig from that initialize view. You don’t need it , pub sub works automatically.

1 Like

I appreciate your help on this. Turns out… The TOP(1) clause was breaking it :speaking_head:

Custom Code:

// **************************************************
// Custom code for APInvoiceForm
// Created: 6/28/2023 2:10:16 PM
// **************************************************

extern alias Erp_Contracts_BO_APInvoice;
extern alias Erp_Contracts_BO_APPromissoryNotes;
extern alias Erp_Contracts_BO_Company;
extern alias Erp_Contracts_BO_Part;
extern alias Erp_Contracts_BO_Vendor;
extern alias Erp_Contracts_BO_LogAPInv;
extern alias Erp_Contracts_BO_Project;
extern alias Erp_Contracts_BO_EmpBasic;
extern alias Erp_Contracts_BO_SupplierXRef;

using System;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Windows.Forms;
using Erp.Adapters;
using Erp.UI;
using Ice.Lib;
using Ice.Adapters;
using Ice.Lib.Customization;
using Ice.Lib.ExtendedProps;
using Ice.Lib.Framework;
using Ice.Lib.Searches;
using Ice.UI.FormFunctions;
using Ice.Lib.Broadcast;

public class Script
{
	// ** Wizard Insert Location - Do Not Remove 'Begin/End Wizard Added Module Level Variables' Comments! **
	// Begin Wizard Added Module Level Variables **

	// End Wizard Added Module Level Variables **

	// Add Custom Module Level Variables Here **

	BAQDataView PartClassBAQDV;

	public void InitializeCustomCode()
	{
		CreatePartClassBAQDV();
		// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Variable Initialization' lines **
		// Begin Wizard Added Variable Initialization

		// End Wizard Added Variable Initialization

		// Begin Wizard Added Custom Method Calls

		// End Wizard Added Custom Method Calls
	}

	public void DestroyCustomCode()
	{
		// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Object Disposal' lines **
		// Begin Wizard Added Object Disposal

		// End Wizard Added Object Disposal

		// Begin Custom Code Disposal

		// End Custom Code Disposal
	}

	public void CreatePartClassBAQDV()
	{
		PartClassBAQDV = new BAQDataView("GI-APInvPartClass");
        oTrans.Add("PartClassBAQDV", PartClassBAQDV);
        string pub1Binding = "APInvDtl.PartNum";
        IPublisher pub1 = oTrans.GetPublisher(pub1Binding);
        if (pub1 == null) 
        {
            string pubName = Guid.NewGuid().ToString();
            oTrans.PublishColumnChange(pub1Binding, pubName);
            pub1 = oTrans.GetPublisher(pub1Binding);
        }
        if (pub1 != null)
            PartClassBAQDV.SubscribeToPublisher(pub1.PublishName, "Part_PartNum");	
	}
}

I added an epiTextBox to the screen and set EpiBinding to PartClassBAQDV.PartClass_Description. Saved the Customization, closed out AP Entry, opened it back up, selected the group and it now works as intended.