I’m running into an issue with event firing. I’ll show you all the issue rather than trying to explain it, and here is my custom code as well:
/********************************************************************************
Summary:
This method checks to see if the customer on the order is eligable to purchase
the part according to the gold or platinum restrictions. Called before "ChangePartNumMaster"
adapter event.
Inputs:
CustomerID, PartNum, BAQ "CUS_isGoldorPlatinum"
Outputs: Message Box Exception if customer cannot purchase the part
Created by: Jeff Gehling
Created on: 1-28-19
Change Log:
Initials Date Description
J.G 1-28-19 Initial Release
***********************************************************************************/
private void GoldOrPlatinumCheck()
{
DynamicQueryAdapter dqa = new DynamicQueryAdapter(oTrans); // For our BAQ to pull information
string baqHelper = "CUS_isGoldorPlatinum"; //The name of the BAQ
EpiDataView orderHead = (EpiDataView)(oTrans.EpiDataViews["OrderHed"]); // We will need the custID
EpiTextBox txtPartNum = (EpiTextBox)csm.GetNativeControlReference("b7505712-6225-4cce-90bb-c39ee8c9efae"); //Get the UI txtbox control
string currCustomer = orderHead.dataView[orderHead.Row]["CustomerCustID"].ToString();
DataTable resultsPlatinumGold;
string currPartNum = txtPartNum.Value.ToString();
bool customerIsGold;
bool customerIsPlatinum;
bool partIsGold;
bool partIsPlatinum;
dqa.BOConnect();
QueryExecutionDataSet myQeds = dqa.GetQueryExecutionParametersByID(baqHelper); //Set the dataset to use BAQ
myQeds.ExecutionParameter.Clear(); // Ensure params are clear
myQeds.ExecutionParameter.AddExecutionParameterRow("PartNum", currPartNum, "nvarchar", false, Guid.NewGuid(), "A"); //pass current part into query partnum param to look up info
myQeds.ExecutionParameter.AddExecutionParameterRow("CustID", currCustomer, "nvarchar", false, Guid.NewGuid(), "A"); //pass current customer into query customer param to look up info
dqa.ExecuteByID(baqHelper, myQeds); //Execute the BAQ with all final params
// Assign BAQ results to local table and assing local variables
resultsPlatinumGold = dqa.QueryResults.Tables["Results"];
customerIsGold = (bool)(resultsPlatinumGold.Rows[0]["Customer_isGoldLevel_c"]);
customerIsPlatinum = (bool)(resultsPlatinumGold.Rows[0]["Customer_isPlatinumLevel_c"]);
partIsGold = (bool)(resultsPlatinumGold.Rows[0]["Part_isGoldLevel_c"]);
partIsPlatinum = (bool)(resultsPlatinumGold.Rows[0]["Part_isPlatinumLevel_c"]);
if (customerIsGold && partIsPlatinum)
{
MessageBox.Show("This part is marked for Platinum customers only", "Epicor Message", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
throw new Ice.BLException("This part is marked for Platinum customers only");
}
if ((!customerIsGold && !customerIsPlatinum) && (partIsGold || partIsPlatinum))
{
MessageBox.Show("This part is marked for Gold or Platinum customers only", "Epicor Message", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
throw new Ice.BLException("This part is marked for Gold or Platinum customers only");
}
}
private void oTrans_ordAdapter_BeforeAdapterMethod(object sender, BeforeAdapterMethodArgs 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 "ChangePartNumMaster":
GoldOrPlatinumCheck();
break;
}
}
The expected correct behavior when the user types in the part:
Yes it does. I also threw message boxes and the search does call that method. I’m thinking it’s something to do with capturing the part num the user selects in the search, then passing that to my query.
Looks like you are trying to grab your part number from the text box value right? I bet the search does it’s work and then populates the text box. Did you try a message box with the value of the text box right before you need it? See if that value is there when you are expecting it.
I can get a msg box to appear if I put the statement at the top of the method. The moment I put it after the currPartNum assignment it does not appear to tell me the current part num
Well, you should still get a message box though. Even if the part number is blank, it should come back blank. That doesn’t make sense why your code would just silently stop.
Another random thought, since this is on a method, could you run a BPM instead? Don’t know if it would be better or not, but another way to skin a cat if this doesn’t work. You will probably have access to the proposed part number a little easier.
I could, but I walked into an organization that has had too many redundant BPMs and poorly written ones at that, that also were tanking performance, so I’m trying to keep things client side as much as possible. I will try a BPM though to see if that approach can do the job.
One more thought before I go to bed is there an args.proposedValue that can be used on a before method call? I’m wondering if you can use that to get the part number more reliably…
And one more thing. Does it behave the same way if you right click in the field and open with part number search?
Jeff,
I agree that this event behavior is very strange, but you might want to try a different solution.
Just my humble opinion but I think I would do this with a BPM Method Directive. I’ve done something similar with checking for the on hand/availability of the part and any Alternate parts, if there is no on hand or availability and there is an Alternate part then I pop up a message alerting the user to click on the Alternate part button to review alternate option. Another one (pre) that checks to make sure the part number does not include any ‘illegal’ characters, and another (post) that overrides the Order Lines Product Group in certain cases.
I used a Method Directive on SalesOrder.ChangePartNumMaster.
I found this to be much more reliable, perhaps because it’s server side?