Delete Rows UD Table

I know there are enough posts about this on here but I’m experiencing an odd issue that I think is easily solvable but I’m just missing something. I’m trying to delete rows from a UD table. Using the settings in the images below, and the code below, when I change the CheckBox01 field to true, then update the table, nothing happens aside from the CheckBox01 field being set to true. However, when I then change the next row to true, and update the table, the previously changed row is deleted and the line I just changed is there and the CheckBox01 is true. I’m not able to just delete the row that I changed, only the previously changed row. I’m guessing it’s because I need to use ttResults in the code itself but admittedly I’m not sure how and I keep getting syntax errors whenever I try. I’m going to keep trying but was hoping someone might be able to easily answer it.


using (var txScope = IceContext.CreateDefaultTransactionScope())
{
foreach(var UD02 in (from row in Db.UD02.With(LockHint.UpdLock) where
row.Company == Session.CompanyID && row.CheckBox01 == true
select row))
   {
      Db.UD02.Delete(UD02);
   }
   Db.Validate();
   txScope.Complete();
}

try setting the RowMod to “DELETE” instead of using the delete method

In that BPM since its within the Updatable BAQ remember you need to foreach on ttResults and you should prob mark both ttResults Row and your Db.UD02 row Delete

You might have to make use of

row.SetRowState(IceRowState.Deleted); // MAYBE Depending Sometimes

Also once you do Delete it, the BAQ Might not Refresh itself until you do GetList again.

1 Like

Just to give you an idea of my skill level, here is my interpretation of your suggestion:

using (var txScope = IceContext.CreateDefaultTransactionScope())
{
	foreach(var ttResultsUD02 in (from row in ttResults.Where(
	row.Company == Session.CompanyID && row.CheckBox01 == true)
	select row))
	{
		Db.UD02.Delete(ttResultsUD02);
		ttResults.Delete(ttResultsUD02);
	}

	Db.Validate();
	txScope.Complete();
}

I’m receiving two syntax errors for using “from row” and “select row”
Also, I’m not sure how to set the RowMod to delete. Sorry for the noob-level question here.

Probably more along

using (var txScope = IceContext.CreateDefaultTransactionScope())
{
foreach(var ttResultsUD02 in (from row in ttResults.Where(
	row.Company == Session.CompanyID && row.CheckBox01 == true)
	select row))
{
foreach(var UD02 in (from row in Db.UD02.With(LockHint.UpdLock) where
row.Company == Session.CompanyID && row.SomeKeyField == ttResultsUD02.SomeKeyField
select row))
   {
      Db.UD02.Delete(UD02);
      // Maybe Even  Db.Validate(UD02);
   }
   Db.Validate();
   txScope.Complete();
}
}

You could use SysRowID as your Key Field if its displayed in your BAQ.

1 Like

I really appreciate your help, but I’m still getting the “row” errors. does “from row” and “select row” not apply to ttResults?

{
foreach(var ttResultsUD02 in (from row in ttResults.Where(
	row.Company == Session.CompanyID && row.CheckBox01 == true)
	select row))
{
foreach(var UD02 in (from row in Db.UD02.With(LockHint.UpdLock) where
row.Company == Session.CompanyID && row.SysRowID.Equals( "d6f860c3-55fc-46b7-ad27-4c21fa4f4ce6")
select row))
   {
      Db.UD02.Delete(UD02);
      Db.Validate(UD02);
   }
   Db.Validate();
   txScope.Complete();
}
}

so the ttResults table will hold the column names that you have on your BAQ… I doubt there is a column just name CheckBox01, if you go to the Display Tab it should be something like in my example:

row.TableName_ColumnName, or maybe im wrong.

var query = (from r in ttResults
	where
		r.CCHdr_Company == companyID
		&& r.CCHdr_Plant == plantID
		&& r.CCHdr_WarehouseCode == whseID
		&& r.CCHdr_CCYear == ccYear
		&& r.CCHdr_CCMonth == ccMonth
		&& r.Calculated_CDRMandatory == true
		&& r.Calculated_EnableCDRCode == true
	select r);

foreach (var row in query)
{
	row.CCDtl_CDRCode = selectedReasonCode;
}
1 Like

Is there a reason to not use the BO method widget instead of custom code? I don’t think you can use it for multiple rows, but isn’t it safer to use the BO instead of going direct to the database?

1 Like

And shouldn’t your BPM be on “RunCustom”?

1 Like

The setting a Custom Action in the BAQ update general properties, creating a base process in the RunCustomAction Method and linking the condition to “Invoke BO Method” did the trick. Much easier. I appreciate all the help.

1 Like

Also, if you are going through the BO’s and will be utilizing deleteByID on a record, I’ve found that method was not super reliable (at least on 10.1.400) on UD tables. I would consistently get record not found when using deleteByID even with passing in all appropriate keys.

To get record deletion working smoothly I had to mark the row with “D” then call the update method to delete the record.