C# Form Customization Error: "Row has been changed by another user"

Hello folks, I’m working on a script that does the following in Opportunity/Quote Entry:
1.Save the current QuoteQty.DocUnitPrice value when the QuoteQty.SellingQuantity value is changed.
2.Set the QuoteDtl.OrderQty and QuoteDtl.SellingExpectedQty fields to match QuoteQty.SellingQuantity when it is changed.
3.Show a MessageBox that lists the values of each quantity field.

I’ve written some code that seems like it SHOULD work, but it’s giving me the following error:

From the digging I’ve done so far, it seems like the solution to this involves the GetByID() method on the QuoteQty table. Unfortunately, I don’t know how to call that method in the Script Editor window. I’m looking through the Programmer’s Guide and it mentions calling methods, but lists syntax that only seems to work in the BPM “Execute custom code” box. I’m not sure why the syntax doesn’t work here.

And of course, here is my code so far:

private void QuoteQty_AfterFieldChange(object sender, DataColumnChangeEventArgs args)
{
switch (args.Column.ColumnName)
{
case “SellingQuantity”:

			EpiDataView edvQuoteQty = (EpiDataView)(this.oTrans.EpiDataViews["QuoteQty"]);
			EpiDataView edvQuoteDtl = (EpiDataView)(this.oTrans.EpiDataViews["QuoteDtl"]);

			edvQuoteDtl.CurrentDataRow["OrderQty"] = (decimal)edvQuoteQty.CurrentDataRow["SellingQuantity"];
			edvQuoteDtl.CurrentDataRow["SellingExpectedQty"] = (decimal)edvQuoteQty.CurrentDataRow["SellingQuantity"];
			

			MessageBox.Show("Quote qty " + (decimal)edvQuoteQty.CurrentDataRow["SellingQuantity"] + Environment.NewLine +
							"Order qty " + (decimal)edvQuoteDtl.CurrentDataRow["OrderQty"] + Environment.NewLine +
							"Exp. qty " + (decimal)edvQuoteDtl.CurrentDataRow["SellingExpectedQty"]);
			edvQuoteQty.CurrentDataRow["DocUnitPrice"] = MyDocUnitPrice;
			edvQuoteDtl.CurrentDataRow["DocExpUnitPrice"] = (decimal)edvQuoteQty.CurrentDataRow["DocUnitPrice"];
			
			break;
			
	}

oTrans.Update();
change the OrderQty and SellingExpectedQty fields
oTrans.NotifyAll();

I tried that, but it didn’t seem to work. :frowning:

This should work for you.

case "SellingQuantity":
			EpiDataView edvQuoteQty = (EpiDataView)(this.oTrans.EpiDataViews["QuoteQty"]);
			EpiDataView edvQuoteDtl = (EpiDataView)(this.oTrans.EpiDataViews["QuoteDtl"]);
			edvQuoteDtl.CurrentDataRow["OrderQty"] = (decimal)edvQuoteQty.CurrentDataRow["SellingQuantity"];
			edvQuoteDtl.CurrentDataRow["SellingExpectedQty"] = (decimal)edvQuoteQty.CurrentDataRow["SellingQuantity"];
			edvQuoteQty.CurrentDataRow["DocUnitPrice"] = MyDocUnitPrice;
			oTrans.Update();
			edvQuoteDtl.CurrentDataRow["DocExpUnitPrice"] = (decimal)edvQuoteQty.CurrentDataRow["DocUnitPrice"];
			break;

	}

Dan, that works perfectly! But why does it work? Does placing the Update() before updating the DocExpUnitPrice separate that line into its own transaction? If so, why?

The DocExpUnitPrice is based on Expected Qty and when Expected Qty changes, you must update to basically commit the latest value before that field can process its logic. Make sense?

1 Like

Ahhh got it, that makes perfect sense. Thanks!