ABL to CSharp how to add a new record to UD08

I am trying to update ABL code to C#. This particular BPM is part of a customization for “training”. I was able to work out the beginning code - however I am stuck at the part where I would like to create a new record and store data in the new record.

Here is what I have at this point:

string sModule=string.Empty;
string sCompanyID=string.Empty;
string sRoleID=string.Empty;
string sRowMod=string.Empty;
DateTime? dAdded=null;

Ice.Tables.UD103A UD103A;
Ice.Tables.UD08 UD08;

foreach(var ttUD100A_xRow in ttUD100A)
{
if(ttUD100A_xRow != null)
{
var ttUD100ARow=ttUD100A_xRow;
sRoleID = ttUD100ARow.Key1;
sModule = ttUD100ARow.ChildKey1;
dAdded = ttUD100ARow.Date01;
sRowMod = ttUD100ARow.RowMod;
sCompanyID = ttUD100ARow.Company;

	switch(sRowMod)
	{
		case "U":
			foreach(var UD103A_xRow in Db.UD103A.Where(a => a.Company == sCompanyID && a.ChildKey1 == sRoleID))
			{
				var UD103ARow = UD103A_xRow;
				foreach(var UD08_xRow in Db.UD08.Where(b => b.Company == sCompanyID && b.Key1 == UD103ARow.Key1 && b.Key3 == UD103ARow.ChildKey1 && b.Key2 == sModule))
				{
					var UD08Row = UD08_xRow;
					UD08Row["Checkbox01"] = UD103ARow["Checkbox01"];
					UD08Row["Checkbox02"] = UD103ARow["Checkbox02"];
					UD08Row["Checkbox03"] = UD103ARow["Checkbox03"];
				}
			}
		break;
		case "A":
			foreach(var UD103A_xRow in Db.UD103A.Where(a => a.Company == sCompanyID && a.ChildKey1 == sRoleID))
			{
				var UD103ARow = UD103A_xRow;
				foreach(var UD08_xRow in Db.UD08.Where(b => b.Company == sCompanyID && b.Key1 == UD103ARow.Key1 && b.Key3 == UD103ARow.ChildKey1 && b.Key2 == sModule))
				{
					var UD08Row = UD08_xRow;
					UD08Row["Checkbox01"] = UD103ARow["Checkbox01"];
					UD08Row["Checkbox02"] = UD103ARow["Checkbox02"];
					UD08Row["Checkbox03"] = UD103ARow["Checkbox03"];
				}
				//I would like to add a new UD08 record here. The following is the ABL Code I am trying to convert.
				// create UD08.
				//assign UD08.Company = sCompanyID.
				//assign UD08.Key1 = UD103A.Key1.
				//assign UD08.Key2 = sModule.
				//assign UD08.Key3 = sRoleID.
				//assign UD08.Key4 = "".
				//assign UD08.Key5 = "".
				//assign UD08.Date01 = dAdded.
				//assign UD08.CheckBox01 = UD103A.Checkbox01.
				//assign UD08.CheckBox02 = UD103A.Checkbox02.
				//assign UD08.CheckBox03 = UD103A.Checkbox03.
			}
		break;
	} //switch(sRowMod)	

} //if(ttUD100A != null)

}

I need to create a new UD08 record and I’m struggling trying to find examples.

Thanks,
DaveO

Hi Dave,

Try something like this:

Ice.Tables.UD08 UD08;
UD08 = new Ice.Tables.UD08();
Db.UD08.Insert(UD08);
UD08.Company = sCompanyID;
UD08.Key1 = UD103A.Key1;
UD08.Key2 = sModule;
UD08.Key3 = sRoleID;
UD08.Key4 = "";
UD08.Key5 = "";
UD08["Date01"] = dAdded;
UD08["CheckBox01"] = (bool)UD103A["Checkbox01"];
UD08["CheckBox02"] = (bool)UD103A["Checkbox02"];
UD08["CheckBox03"] = (bool)UD103A["Checkbox03"];

Mr. Carlos: Thank you so much for the reply and code sample.

I must admit (and I’m sure you have guessed) I am not a full time coder and I am wondering about the SysRevID and SysRowID.

Do I need to execute a BO for those numbers to be generated? Or is there some background process that creates those numbers?

Thank you again,
DaveO
Ph: 651-246-3281

Those are triggered automagiacally in the background on a row creations. SysRev is basically a how many times has the row been touched (serves no purpose to you, at least I’ve never needed to use it) and SysRow is like the auto increment unique identifier for that row. Nothing need be done manually, so long as you go through the BO. Even if you bypassed the BO it may be an SQL trigger I can’t remember at the moment.

Joshua Giese
Technology Solutions : CTO
Direct Phone: 920.593.8299
Office Phone: 920.437.6400 x342
[http://wcibags.com/email/emailFooter4.jpg]http://www.wcibags.com/

Mr. Joshua: Thank you for the reply.

Do you know if I run C# code from a BPM that adds a record - does the SysRevID and SysRowID get created?

Thanks,

DaveO

Yes it does, however the method outlined here is bypassing the business objects. With UD tables that is not a HUGE deal and Epicor does put some checks and balances in place. But any time you are inserting into an Epicor Object you should use the business objects to do so.