Clearing a Table

Thought I had this working but it appears I was mistaken.

I’m working in an updateable BAQ using a BPM. My goal is to clear the UD15 table of its current data and then refill it with the new information that I would like to use. Currently, I am simply trying to clear the table out. My goal at the end of this is to have a completely empty UD15. I am using the query to fill the table and setting all rowMod to “D”. I’m then using the BO to UpdateExt on UD15. Is there something wrong with this setup or is there an easier way to do it? Any help would be greatly appreciated.


1 Like

DMT is way easier. You just get the Keys and pass in with the delete check box.

While this might be easier for a one time usage, unless I’m mistaken, this won’t work for what I’m doing as I’m hoping to add custom code after this to then populate the UD15 table. End goal would be to be able to run something that would clear the table and fill it with the new information without having to use a separate tool to clear the target table first.

Sorry, I thought this was a one time thing. I didn’t get that you were clearing it out over and over.

I’m not sure how you would do this with a widget, I usually just jump to a code block to do it.

Not sure about the widgets, but here’s a code block to do it:

foreach(var udrow in(
  from ud13 in Db.UD13.With(LockHint.UpdLock)
  select new {ud13}))
using(var udBO = Ice.Assemblies.ServiceRenderer.GetService<Ice.Contracts.UD13SvcContract>(Db))
{
  UD13Tableset udTS = new UD13Tableset();
  udTS = udBO.GetByID(udrow.ud13.Key1, "", "", "", "");
  
  udTS.UD13[0].RowMod = "D";
  
  udBO.Update(ref udTS);
}

Make sure to add usings and references.

using Ice.Tablesets;

Add the UD15 Assembly.

Before

After

No problem whatsoever. I appreciate the reply and I wasn’t overly clear. I’m not opposed to using a code block, but I’ve tried code in both BPM and Customization with the effect being that the code runs, appears to do something, but then when I check the table, the previous data is still there. I’m trying this way now since none of my code seems to have the desired effect.

Try using DeleteById instead of UpdateExt

Considered Using DeleteByID but I couldn’t get it to work in my code and as far as using the Invoke BO Method, I didn’t see a way to loop through the records to delete them all.

This reply was for another comment. I put it under the wrong one.

DeleteById would work too and would be less lines of code. I don’t delete things often, so I forget that’s a thing.

foreach(var udrow in(
  from ud13 in Db.UD13.With(LockHint.UpdLock)
  select new {ud13}))
using(var udBO = Ice.Assemblies.ServiceRenderer.GetService<Ice.Contracts.UD13SvcContract>(Db))
{
  UD13Tableset udTS = new UD13Tableset();
  udTS = udBO.DeletetByID(udrow.ud13.Key1, "", "", "", "");
}

The first set of code appeared to work until I checked the UD15 with a separate BAQ which showed the old information still in it. Also if ran in a dashboard, it showed the old data. If ran in a BAQ, I received the same results as yours, until I checked it with the other or used it in the dashboard.

The second set of code I received the error Cannot implicitly convert type ‘void’ to Ice.Tableset.UD15Tableset

Also the error on the typo (DeletetByID) but that one I found easily but this one is eluding me more.

What BO are you calling it on?
I ran mine on the GetList Post.

I was running it on the GetList Base. Will move it to Post and see if that makes the difference.

@TDray Since it is a UD table you could just clear the table like this.

foreach (var _UD15 in Db.UD15)
{
    Db.UD15.Delete(_UD15);
}
2 Likes

I moved it to the Base and same results. I am getting a record not found popup then the query response of 0 found.

My mistake–the second query I pulled up to validate was one that was already in the system. Turns out it had a criteria to filter records that weren’t entered today. Whoops.
I’ll take a look again tomorrow if someone else doesn’t get to it first.

I tried this on a post process on GetList and it did not work. I then tried it as a base process on GetList and it worked! Thank you so much for your help.

Gpaynes solution worked but thank you so much for your help as well.

1 Like

suggest making it a little better to make sure that everything is in a scope… here is another version that should work:

using (var x = Ice.IceDataContext.CreateDefaultTransactionScope()){
    foreach (var ud15 in Db.UD15)    {
        Db.DeleteObject(ud15);
    }
    Db.Validate();
    x.Complete();
}
1 Like

Thanks Tim. This worked as well so I’m going to take your advice and use this to make sure it is in a scope.

1 Like