UD100/UD100A Auto Increment

I have worked through the code to Auto Increment the UD100 table using a Post Processing Directive. While this is not optimal (because of the potential to create a duplicate entry), I think it will work well enough as the data entry screen will be used primarily by only one user at the shipping station.

What I am looking to do now, is also auto increment the UD100A table rows that are tied to the UD100 row (starting with Line 1 - ChildKey1 - and incrementing by 1 for each new addition). I have gotten as far as duplicating the UD100 code (see below):

UD100 GetNewUD100 - Post Process BPM:

//β€” Ice.Tables.UD100
//β€”
//β€” Auto Increment Key1 Value for Transfer Shipment Entry, Parent Table

foreach (var ttUD100_Recs in (from ttUD100_Row in ttUD100
where ttUD100_Row. Company == Session.CompanyID
&& string.Equals(ttUD100_Row.RowMod, IceRow.ROWSTATE_ADDED, StringComparison.OrdinalIgnoreCase)
select ttUD100_Row))
{
var ttUD100Row = ttUD100_Recs;
if (ttUD100_Recs != null)
{
Ice.Tables.UD100 UD100;
var UD100_Recs = (from UD100_Row in Db.UD100
where UD100_Row.Company == Session.CompanyID
orderby UD100_Row.Key1 descending
select UD100_Row).FirstOrDefault();
{
var UD100Row = UD100_Recs;
if (UD100_Recs == null)
{
ttUD100Row.Key1 = β€œ100001”;
}
else
{
ttUD100Row.Key1 =(System.Convert.ToInt32(UD100_Recs.Key1)+ 1).ToString();
}
}
}
}

UD100 GetNewUD100A - Post Process BPM:

//β€” Ice.Tables.UD100A
//β€”
//β€” Auto Increment Key1 Value for Transfer Shipment Entry, Parent Table

foreach (var ttUD100A_Recs in (from ttUD100A_Row in ttUD100A
where ttUD100A_Row. Company == Session.CompanyID
&& string.Equals(ttUD100A_Row.RowMod, IceRow.ROWSTATE_ADDED, StringComparison.OrdinalIgnoreCase)
select ttUD100A_Row))
{
var ttUD100ARow = ttUD100A_Recs;
if (ttUD100A_Recs != null)
{
Ice.Tables.UD100A UD100A;
var UD100A_Recs = (from UD100A_Row in Db.UD100A
where UD100A_Row.Company == Session.CompanyID &&
UD100A_Row.Key1 == ttUD100ARow.Key1
orderby UD100A_Row.ChildKey1 descending
select UD100A_Row).FirstOrDefault();
{
var UD100ARow = UD100A_Recs;
if (UD100A_Recs == null)
{
ttUD100ARow.Key1 = β€œ1”;
}
else
{
ttUD100ARow.Key1 =(System.Convert.ToInt32(UD100A_Recs.Key1)+ 1).ToString();
}
}
}
}

Being kind of new to all of this, I am getting an error when I go to add the new child to the parent table:

The INSERT statement conflicted with the FOREIGN KEY constraint β€œFK_UD100A_UD100”. The conflict occurred in database β€œE10-TestDB”, table β€œIce.UD100”.
The statement has been terminated.

There is probably an easy way to sync the two tables. Looking for help to trouble shoot and solve the problem.

Thanks!

You cant change the parent Key of the child without breaking the link. I think you are intending to change the ChildKey1?

:roll_eyes:

Thanks Chris!
Made the change to the UD100A code from Key1 to ChildKey1 in the if-then-else statement and the BPM is working great now.

No problem Buddy, Do you know how to mark a solution on the forum?