Sales Order Update Conflict in Customization

Good morning experts! Hope everyone had a great 4th of July!

I try to research as much as I can before posting to this forum, so when I do it’s because I couldn’t find the answers in the Google-verse. This forum has helped me out so much, and I hope to be able to contribute to helping others some day. Today, however, I need some more expertise.

We have added install date fields on the Header and Lines area of our Sales Order Entry form…

I created custom code in the oTrans_ordAdapter_AfterAdapterMethod event handler, under the “Update” call, that looks for changes in these fields when a user clicks Save. If changes exist, it prompts the user to update the dates on the line items, similar to the standard Epicor message when dates are changed…

At the end of the custom code I use oTrans.Update() and oTrans.Refresh() to set the code and refresh the form to show the changes.

Everything works great, until a user changes both the standard “Ship By” date field and any of the custom install date fields…

When the user clicks the Save button, they are prompted with the custom prompt to change line item dates, followed by the standard prompt to change the dates…

After that I get the error (which I imagine is because of the custom code oTrans.Update() and oTrans.Refresh())…

I click OK on the error message and a little bit later the standard prompt to change the dates pops up again. I click Yes and get my custom prompt once more. I click Yes on that and then all the dates change back to what they originally were. What I think is happening is that the custom date updates, then the standard date tries to update before the form refreshes and the error triggers, then things start refreshing and updating and the code thinks the dates have changed again. It’s a mess, and I can’t figure a way around it. I did originally try this with a Method Directive BPM on the SalesOrder.MasterUpdate, both on the Pre and Post-Processing side and had the same errors. I then tried it with a Data Directive BPM on OrderHed In-Transaction, with errors as well.

Below is my current code being used. Note the value from the form field is sent to a module, “dtConversion”, that converts it into a date format that is assigned to the “tempSchInst” variable. I did this to keep all dates the same (e.g., “MM/dd/yyyy”).

private void oTrans_ordAdapter_AfterAdapterMethod(object sender, AfterAdapterMethodArgs args)
{
// ** Argument Properties and Uses **
// ** args.MethodName **
// ** Add Event Handler Code **

// ** Use MessageBox to find adapter method name
// EpiMessageBox.Show(args.MethodName)
// MessageBox.Show(args.MethodName);
switch (args.MethodName)
{
case “Update”:
Boolean showPrompt = false;

  	// Check to see if any of the Install date values changed on the Header...
  	string tempSchInst = "";
  	if (dteInstSched.Text != "" && dteInstSched.Text != "__/__/____")
  	{
  		tempSchInst = dtConversion(dteInstSched.Text);
  		if (schedInstallValue != tempSchInst)
  		{
  			showPrompt = true;
  			schedInstallValue = tempSchInst;
  		}
  	}
  	// If any Install dates changed, then prompt user to change all line items...
  	if (showPrompt == true)
  	{
  		String promptMessage = "You have changed the following fields: Sch. Install, Install Start, and/or Install Finish. ";
  		promptMessage += "Do you want to refresh the lines currently assigned to the previous date with the new date?";
  		DialogResult dialogResult = MessageBox.Show(promptMessage, "Install Dates Changed", MessageBoxButtons.YesNo);
  		if(dialogResult == DialogResult.Yes)
  		{
  			//do something if yes...
  			foreach(DataRow dr in edvOrdDtl.dataView.Table.Rows)
  			{
  				if (dr["InstallSchDate_c"].ToString() == "") // If the Lines date equals nothing
  				{
  					if (dr["InstallSchDate_c"].ToString() != tempSchInst) // If Lines date doesn't match the Header field
  					{
  						edvOrdDtl.dataView[0].BeginEdit();
  						dr["InstallSchDate_c"] = tempSchInst;
  						edvOrdDtl.dataView[0].EndEdit();
  						oTrans.Update();
  					}
  				}else // The Lines date has a value
  				{
  					DateTime instDate = (DateTime)dr["InstallSchDate_c"];
  					string insDate = instDate.ToString("MM/dd/yyyy");
  	
  					if (insDate != tempSchInst) // If Lines date doesn't match the Header field
  					{
  						edvOrdDtl.dataView[0].BeginEdit();
  						dr["InstallSchDate_c"] = tempSchInst;
  						edvOrdDtl.dataView[0].EndEdit();
  						oTrans.Update();
  					}
  				}
  			}
  			showPrompt = false;

// oTrans.Update();
oTrans.Refresh();
}
}

  	break;

Thanks for your time and any help you can provide on this! Have a great day!

Shawn

Hey Shawn,

Hopefully someone will chime in with a solution that may be more palatable than the following.
First, I’m on E9, but I suspect you’re experiencing the same issues I am/was; competing with Epicor for control of the sales order header and detail records.

I am in the process of using a UD table to store all of my company-specific data in sequence with a sales order - create a new order, create a new UD header. Create a new detail, do the same.

When the order is “occurring” (many changes from order receipt to picking), I don’t have to worry about the Epicor record’s update state. I can write what I need to, when I need to. All I have to do is intercept the create-new, and record deletion methods/events (via BPM) and the records will remain in sync. I can update “my records”, when I need to.

This follows advice I received (from @rbucek) when I posted on this topic:

Now, for your purposes, updating the OrderHed/OrderDtl records via customization may be the appropriate course, just be aware that you will be competing with Epicor for control of those records every step of the way.

1 Like