I have a data directive on UD100 to auto increment Key1. The code syntax checks out ok and Key1 is auto incrementing as expected once I manually enter the first records value. However when I run validate I get the error “Index was outside the bounds of the array”. I used code found in an older post that was for a Method Directive but I had issues with the MD so switched to a DD which got me farther - UD100/UD100A Auto Increment
I saw some posts that talked about tuple limit and this is way beyond my technical knowledge. Can anyone help? Below is the full code.
//— Ice.Tables.UD100
//—
//— Auto Increment Key1 Value for UD100 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();
}
}
}
}
@klincecum - the custom code you provided worked until you get to 10 and then it keeps assigning the number 10 to each row. I am guessing because the Key1 is a string field and the code is converting the number to a .ToString() but am not sure what to do to solve this. The column in the grid also sorts the 10 wrong since the field is string. Any suggestions?
THANK YOU!!! that works. I left it at 10 leading zeros to be safe. This is basically a sequential Request No that will be printed on a form and the Key1 field is the link from the Kinetic Landing Page to the Detail page. Thank goodness for DMT as I utilized it to Add and Delete records for the UD100 table in bulk to test this.
I apologize for taking so long to find this as I know you answered the initial post a while ago. This is a Project I am working in between dealing with issues (mainly Kinetic). I hadn’t entered records past 10 until yesterday.
Sorry @klincecum but the latest code is making the Key1 = 1 for all records.
Original code with one minor change: orderby Convert.ToInt32(ud100Rows.Key1) descending