Update Sales Order

I have used the Wizard to add the Sales Order Adapter Update Method. I want to be able to change the OTS Ship information for a job and update the sales order. I have a DataView of the Order Header. How do I tell it to update a specific field. So for an example I have text box: tbOrderNameUpdateShip.Text that I want to be able to change and then update the Sales Order Header field: OrderHed.OTSName with the change. I think I have everything but how to tell it what fields equal what.

	private void CallSalesOrderAdapterUpdateMethod()
	{
		try
		{
			// Declare and Initialize EpiDataView Variables
			// Declare and create an instance of the Adapter.
			SalesOrderAdapter adapterSalesOrder = new SalesOrderAdapter(this.oTrans);
			adapterSalesOrder.BOConnect();
			//adapterSalesOrder.SalesOrderAdapter.OrderHed.OTSName = tbOrderNameUpdateShip.Text;


			// Call Adapter method
			bool result = adapterSalesOrder.Update();

			// Cleanup Adapter Reference
			adapterSalesOrder.Dispose();

		} catch (System.Exception ex)
		{
			ExceptionBox.Show(ex);
		}
	}

Modify your sales order data from the adapter before the update method. There should be a ton of examples of accessing a adapter data set here

I have been searching for Sales Order Update and Update on here and really haven’t found much in regards to code examples.

I’ll post an example when I get into the office in a bit

The problem is above. .OrderHed is a table, with rows. You have to specific a row you want to modify like:
adapterSalesOrder.SalesOrderAdapter.OrderHed[0].OTSName

How do you know which row? I cant answer that. If there is only 1 I suppose that easy enough.

That’s one of the nice things about using an EDV. The EDV stores the active row:
myEDV.dataView[myEDV.Row][“MyField”]

1 Like

Okay, I am so not following. Probably because I just don’t know much about how to properly write this.

Here is what I have and I am getting an error… ( ‘Erp.Adapters.SalesOrderAdapter’ does not contain a definition for ‘SalesOrderDataView’ and no extension method ‘SalesOrderDataView’ accepting a first argument of type ‘Erp.Adapters.SalesOrderAdapter’ could be found (are you missing a using directive or an assembly reference?)

	{
		try
		{
			// Declare and Initialize EpiDataView Variables
			// Declare and create an instance of the Adapter.
			SalesOrderAdapter adapterSalesOrder = new SalesOrderAdapter(this.oTrans);
			adapterSalesOrder.BOConnect();
			adapterSalesOrder.SalesOrderDataView.OrderHed[0].OTSName = edvGS_Order_Detail_DataView.dataView[edvGS_Order_Detail_DataView.Row]["OrderHed_OTSName"];
			
			// Call Adapter method
			bool result = adapterSalesOrder.Update();

			// Cleanup Adapter Reference
			adapterSalesOrder.Dispose();

		} catch (System.Exception ex)
		{
			ExceptionBox.Show(ex);
		}
	}

You put SaleOrderDataView in there. It should be
adapterSalesOrder.SalesOrderData.OrderHed[0].OTSName

image

All adapters have a DataSet that is generally AdapterTypeName+Data:
SalesOrderData
CustomerData
CustShipData
etc

1 Like

Okay another question. I can’t actually change the text box that is bound to the data view because it is read only and it won’t let me change it. So I was entering the new data into a different text box. How do I tell it I want it to update with that text box?

Depends on what the textbox is bound to, but I’d try setting the dataview value rather than the textboxt text

1 Like

image

Okay, sorry guys. I’m an idiot. My goal is to be able to click a button and have customer service change a Ship to name and then click a button and update the Sales Order Record. On the image above the one marked Data View is attached to the DataView and I cannot change it to be editable. So, in order for Customer SErvice to be able to enter what it needs to change to I was going to have this text box pop up, they enter the data there and then save and I take that data from the text box and update the Sales Order.

You’re not an idiot! This stuff isn’t easy and it takes guts to learn/attempt challenging things.
Is this built on a custom form or a customization on an existing Epicor form?
Breaking this down into its simplest components is where to start. Sounds like you need to have the user enter a value in a field, take that value, and then update a sales order record?
Think like so: store the value of the text box in a variable. Call sales order adapter and find appropriate sales order record. Set sales order record data to variable value, then call update on sales order.

1 Like

Well I know I’m not really an idiot but I haven’t had any formal training in C# or epicor. This is all self taught, learn by doing and googling lol. Frustrating to say the least! It is all hands on deck here at work as we have been implementing for a loong time and the deadline is looming.

Anyway, It is that simple that I just need the user to enter the value in the field. take that value and update the sales order record. This is what I have. I’m not getting any errors but it isn’t doing a darn thing either. Do I have the right syntax and in the right order?

	{
		try
		{
			// Declare and Initialize EpiDataView Variables
			// Declare and create an instance of the Adapter.
			MessageBox.Show("Sales Order Adapter");
			SalesOrderAdapter adapterSalesOrder = new SalesOrderAdapter(this.oTrans);
			adapterSalesOrder.BOConnect();
			var shipname = tbOrderNameUpdateShip.Text;
			adapterSalesOrder.SalesOrderData.OrderHed[0].OTSName = shipname.ToString();
			//adapterSalesOrder.SalesOrderData.OrderHed[0].OTSName = edvGS_Order_Detail_DataView.dataView[edvGS_Order_Detail_DataView.Row]["OrderHed_OTSName"].ToString();
			
			// Call Adapter method
			bool result = adapterSalesOrder.Update();
			MessageBox.Show("Sales Order Adapter After Update");
			// Cleanup Adapter Reference
			adapterSalesOrder.Dispose();

		} catch (System.Exception ex)
		{
			ExceptionBox.Show(ex);
		}
	}```

How do you tell the adapter which sales order record to find? :wink:

1 Like

If this is a BEFORE adapter call, you could check to see which Heads have RowMod = “U” or “A”. However. it gets sneaky, because if you change a Dtl and not the Head, that doesnt work.

If I knew that I wouldn’t be asking for help lol. Okay, so do I need to add a GetbyID or something. I search the DataView and I am on the current record based upon job number. But it isn’t the Data View I’m actually needing to update it’s the sales order record.

These are all on the Order Header. And I will change it before I call the adapter to update it.

Correct

The adapter should already contain your data. Maybe try

var allOfTheseHaveChanged = adapterSalesOrder.SalesOrderData.OrderHed.AsEnumerable().Where(w => w["RowMod"].ToString() == "A" || w["RowMod"].ToString() == "U" );
foreach(DataRow row in allOfTheseHaveChanged)
{
  row["YourField"] = YourData;
}

Better yet - get the current order from the orderhead edv.

var orderHead = oTrans.Factory("OrderHead"); //is this spelled right?
int orderNum = (int)orderHead.dataView[orderHead.Row]["OrderNum"];
var currentOrder = adapterSalesOrder.SalesOrderData.OrderHed.AsEnumerable().Where(w => (int)w["OrderNum"] == orderNum).FirstOrDefault(); 
if(currentOrder != null)
{
currentOrder["YourField"] = YourData;
}
1 Like

So, what does that block of code replace? What do I plug into the places where you have YourField, YourData, etc.
I’m so lost! My apologies…

YourField = the field in orderhead you want to change
YouData = the data you want to place in the aforementioned field