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]')
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.
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?
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.
I appreciate your help on this. Turns out… The TOP(1) clause was breaking it
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.