Delete sales order via c# customization

Would anyone know what is the proper c# code to delete an order in a customization? This doesn’t work:

Int SONum = 1234567;
SalesOrderAdapter SO = new SalesOrderAdapter(this.oTrans);
SO.BOConnect();
SO.DeleteByID(SONum);

And this doesn’t work:

Int SONum = 1234567;
SalesOrderAdapter SO = new SalesOrderAdapter(this.oTrans);
SO.BOConnect();
SO.GetByID(SONum);
SO.SalesOrderData.Tables["OrderHed"].Rows[0]["RowMod"] = "[Delete]";
SO.Update();

And this doesn’t work:

Int SONum = 1234567;
SalesOrderAdapter SO = new SalesOrderAdapter(this.oTrans);
SO.BOConnect();
SO.GetByID(SONum);
SO.SalesOrderData.Tables["OrderHed"].Rows[0]["RowMod"] = "D";
SO.Update();

If anyone can advise, I would be appreciative. Thanks.

Just a swag here but would you not need to add RowMod = D for OrderDtl and OrderRel and perhaps OrderRepComm?

I only have the OrderHed record to remove, none of the other tables are populated.

Try this

SalesOrderAdapter SO = new SalesOrderAdapter(this.oTrans);
SO.BOConnect();
SO.GetByID(SONum);
SO.SalesOrderData.OrderHed[0].Delete();
SO.Update();
4 Likes

That worked! Thanks Jose.

Dan,
As an aside, I am piqued as to whether Jose’s solution will work on a fully-populated order. I will try when I have some free time, just for grins and giggles.

1 Like

@BBussey Good question. It goes through the BO so I assume if you can delete a fully populated order in the GUI that this would work as well but defintely share your results please!

It will that just calls the same business logic as hitting delete in the UI.
It will work as long as there are no referential integrity issues related (Jobs, POs etc)

Jos? C Gomez
Senior Software Engineer

2 Likes