What is the correct way to delete a row with a bpm?

In this case I am using UD20 for an approval process. Once something needs approval a bpm adds a row to UD20. When the request is either approved or unapproved, and it has updated the specific table, I have a bpm delete the row. Here is my question, Is the below code I am using the best way to achieve this?

var tempUD20Row = ds.UD20.FirstOrDefault();
string key1 = (string)tempUD20Row.Key1;
string key2 = (string)tempUD20Row.Key2;
string key3 = (string)tempUD20Row.Key3;
string key4 = (string)tempUD20Row.Key4;
string key5 = (string)tempUD20Row.Key5;

var thisUD20Row = Db.UD20.Where( row => row.Key1 == key1 && row.Key2 == key2 && row.Key3 == key3 && row.Key4 == key4 && row.Key5 == key5 ).FirstOrDefault();
if((thisUD20Row != null))
{
    Db.DeleteObject(thisUD20Row);
}

In another customization I want to do a similar thing with OHOrderHedMsc rows. In that case I want to make sure a specific volume discount charge applies to said order and make sure no other volume discount charges exist on said order. I don’t have a code snippet for that yet, as I really want to make sure I understand the correct way to go about it.

I’d really appreciate anyone’s advice, feedback and ideas. Thanks.

Since it’s a UD table you are probably okay doing it this way, but typically you want to call the BO’s Update method and pass in a RowMod = “D”. You should be able to find some code for that on this site.

2 Likes

There should be a DeleteByID method on the BO

3 Likes

What about deleting a QuoteMsc or OrderMsc row? I don’t believe there is a method for that. And I was having issues passing in RowMod = “D”.

Have you run a trace through the application? That is going to be the best way to find the methods you need. You’ll just have to mentally filter out the noise of some UI specific methods that get called.

4 Likes

Can someone explain how the Db[dot]Method works? For example “Db.Validate();”.

Db.Validate();

Ice Tools documentation seems to just elude to making sure the data that is currently in the row(s) you have modified, abides by the underlying table rules/required fields/formats before committing the data. The method/function is available as something to call for that class/object. In this case I’m assuming that Db.Validate() has the ability to pick up the context of the rows used that way you don’t have to specify and say something like:

Db.OrderHed.Validate(OrderHedRow)
Db.OrderDtl.Validate(OrderDtlRow)

For any future readers, please avoid using Db.DeleteObject(); as there are better ways to accomplish the same thing.

var tempUD20Row = ds.UD20.FirstOrDefault();
string key1 = (string)tempUD20Row.Key1;
string key2 = (string)tempUD20Row.Key2;
string key3 = (string)tempUD20Row.Key3;
string key4 = (string)tempUD20Row.Key4;
string key5 = (string)tempUD20Row.Key5;

var thisUD20Row = Db.UD20.Where( row => row.Key1 == key1 && row.Key2 == key2 && row.Key3 == key3 && row.Key4 == key4 && row.Key5 == key5 ).FirstOrDefault();
if((thisUD20Row != null))
{
    // Don't Use This - Db.DeleteObject(thisUD20Row);
    // Instead Use This
    using(var UD20svc = ServiceRenderer.GetService<UD20SvcContract>(Db))
    {
        UD20svc.DeleteByID(key1,key2,key3,key4,key5);
    }
}

Note: In “Usings & References…” you’re going to want to add the following to “Usings”

using Ice.Assemblies;

and add the following Assemblies to “References”
Click the Add button and find “Ice.Contracts.BO.UD20” (You may have to wait for it to find it)

Full Disclosure: Unless @josecgomez (The Epicor King) says, there is most likely a better way :rofl:, and I want to hear all about it.

3 Likes
1 Like