Customization or BPM to set PayFlag upon creation of Sales Order

Hello Everyone,

I am attempting to modify a customization that was created before my time with my company. This customization does work in its current context. It was designed to set the PayFlag under Order Entry > Header Tab > Header Manifest Billing Tab > Billing tab to “TP” for Third Party when the customer number in the list of hardcoded customer numbers in the customization is set. The issue I am having is that we are now utilizing EDI and when Sales Orders are created via EDI, this customization does not set the PayFlag. I have been trying to rework it via a BPM, Data Directive, or modifying the customization with no luck so far.

I am open to any options, we just need this automation to be in place to save us from having to modify a lot of orders that EDI creates. Does anyone have any insight on how to do this? I am not a very experienced customization developer so my knowledge is limited. This customization fires off as soon as I enter the CustID in the SoldTo box in Sales Order Entry and returns the message box saying “Third Party Has Been Set”

Here is the customization that is working when we manually create Sales Orders:

private static void OrderHed_AfterFieldChange(object sender, DataColumnChangeEventArgs args)
{
// ** Argument Properties and Uses **
// args.Row[“FieldName”]
// args.Column, args.ProposedValue, args.Row
// Add Event Handler Code
List ThirdPartyVendors = new List{“2000”, “3100”, “4000”, “7950”, “6700”, “6710”, “1080”, “2840”, “1077”, “1076”, “2010”, “1075”};

	switch (args.Column.ColumnName)
	{
		case "CustomerCustID":
			if(ThirdPartyVendors.Contains((string)edvOrderHed.CurrentDataRow["CustomerCustID"])
			)
			{
				edvOrderHed.CurrentDataRow.BeginEdit();
				edvOrderHed.CurrentDataRow["PayFlag"] = "TP";
				edvOrderHed.CurrentDataRow.EndEdit();
				MessageBox.Show("Third Party Has Been Set");
			}
			break;
		case "ShipToNum":
		case "BTCustID":
			if(ThirdPartyVendors.Contains((string)edvOrderHed.CurrentDataRow["CustomerCustID"])
			)
			{
				edvOrderHed.CurrentDataRow.BeginEdit();
				edvOrderHed.CurrentDataRow["PayFlag"] = "";
				edvOrderHed.CurrentDataRow.EndEdit();
				edvOrderHed.CurrentDataRow.BeginEdit();
				edvOrderHed.CurrentDataRow["PayFlag"] = "TP";
				edvOrderHed.CurrentDataRow.EndEdit();
				MessageBox.Show("Third Party Has Been Set");
			}
		break;
	}
}

private static void edvOrderHed_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.AddRow))
	{
		if ((args.Row > -1))
		{
		}
	}
}

}

Thank you!

Hey Josh,

This is why the recommendation is to use BPMs instead of screen customizations. In fact, this won’t work in the browser at all. There are a lot of examples of BPMs setting fields conditionally here on the site.

1 Like

@jscheffler I would put this post processing on SalesOrder.ChangeCustomer for normal processing to future proof the sales order entry process.

EDI does as you have seen bypass all of the salesorder processing, so you will need the same ish routine on DemandImportEntry.ImportProcessingDemand. This is the header section of my routine which is based on the thread below.

/* transfer from demand to order */



var DemandHeadRow =
  (from row in Db.DemandHead.With(LockHint.NoLock)
  where
    row.SysRowID == DemandHeadRowid
    && row.EDIOrder == true
    
  select row
  ).FirstOrDefault();

if (DemandHeadRow != null)
{
  
        /* Copy cust profile to sales order */

      var orderHedRow = Db.OrderHed.Where(oh => oh.Company == DemandHeadRow.Company && oh.OrderNum == DemandHeadRow.OrderNum ).FirstOrDefault();
      {
          using (System.Transactions.TransactionScope txScope = IceDataContext.CreateDefaultTransactionScope())//start the transaction
          {
               var Customer = Db.Customer.Where(Customer_Row => orderHedRow.CustNum == Customer_Row.CustNum && orderHedRow.Company == Customer_Row.Company).FirstOrDefault();
              {
                              
                  var shiptoRow = Db.ShipToMFBill.Where(st => st.Company == Session.CompanyID && st.CustNum == Customer.CustNum && st.ShipToNum == orderHedRow.ShipToNum).Select(st => new { st.PayBTFlag, st.PayAccount}).FirstOrDefault();
                  if (shiptoRow != null)
                  {
                    orderHedRow.PayFlag = shiptoRow.PayBTFlag;
                    orderHedRow.PayAccount = shiptoRow.PayAccount;
                    Ice.Diagnostics.Log.WriteEntry($" custID {Customer.CustID} PayAccount  {orderHedRow.PayAccount}");
                  }
              
              }
              txScope.Complete();//commit the transaction
          }
      }
    
}

2 Likes

I’d probably do something similar to this:


The query looks like:

This determines if TP should be set, then this sets it.

Note, I say all rows because experience has shown that changed row doesn’t include added rows (though you would think it should).

You can further refine this to look at the billto if that also can control it and even issue the popup message if you want.

1 Like

Hi Marjorie,

I followed your setup for a Method Directive on SalesOrder.Update. I receive this error. In my query ttOrderHed and customer are linked by CustNum. 3P is the name of the Method Directive I created.

Here is my setup:



Do you have quotes around the customer IDs?