Checking part attribute at time of part entry on the sales order line - event firing question

Hey Everyone!

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:

    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.
    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;

    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":

The expected correct behavior when the user types in the part:

When the search button is used INCORRECT behavior nothing happens:

Shouldn’t both be calling the same method? Does it have to do with the way I am capturing the part number initially?

I’m assuming you ran a trace on both ways to see which method is called… Does that show the same method for both :face_with_raised_eyebrow:

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 did! I tried to show a msg box with the current part but no msg box ever appeared.

I thought you said you did get message boxes to pop up?

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

That’s wierd. So if the message box is the line before the current number assignment it works. But it’s the line after, no message box at all?

Correct! I may need to parse the where clause out somehow to get the part number at this point. I’m just not sure. Ahhh love me a good puzzle.

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.

That’s what I was thinking too. Theres got to be one special thing I’m missing here.

Have you tried and else statement at the end of the ifs to pop a message no matter what? So even if the part is ok?

I haven’t tried that yet but I will and report back

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.

1 Like

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… :thinking:

And one more thing. Does it behave the same way if you right click in the field and open with part number search?

Ok, I need to go to bed…

I do too. I’ll try all these ideas tomorrow am lol

Damn, I can’t get any of these things to work after testing today. Hmmmmm.

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?