Can anyone help me with a little code… I’m currently in GetaNewUD30 - Post Processing
I have a variable of LoadNum and I need to get that Field which is LoadNum_c on UD30_UD with the following ABC10001 etc it also sets the Key1 on UD30 before setting LoadNum_c
Here is what I got already… I had a similar issue which was resolved but now I’m adding a prefix which is making it even more complex.
Is it your desire that the “highest” (alpha-numberically) key with a specified prefix be incremented?
Like if you have UD30 records with Key1: 1001, 1100, TEA111, and TEA1111
And you add a record with prefix TEA, the Key1 field for that ne record would TEA1112 ??
"TEA"+"1112" where the "1112" is 1) "1111" converted to a number, 2) that number incremented by 1, and finally 3) converted back to a string
Can you just make Key1 your prefix in Key2 the sequence?
That would make things a tad easier.
Either way, you have the issue of the number of digits in the “numeric part”, and the fact that the whole thing is a string. sorting the numeric part would go: 1, 10, 100, 101, 102, ...109, 11, 110, 111, 112... 119, ...
So you might want to pad the numeric part with leading zeros. Then the “Order By” in the LINQ query would be straightforward.
I simply want to set Key1 to TEA1000 and when a user presses New it will create TEA1001 and so on.
I’m guessing this would become very difficult because it’s a string? Is there no way to write so it will automatically increment? I tried copying and modifying your last help but it messed it all up because it was a string and not an number field.
Do you have any example code that could kick start me? Happy to fill in the blanks and may need to ask you more questions.
If yes to varying prefixes, then the LINQ query would have the Where clause include a match for the prefix as well. If the desired prefix was TEA (and the records above already existed), The query would return "TEA0002". You could then take that result and use a string substitution (subbing “”for“TEA”). Then you'd have the string "0002"which could be converted to an integer. From there you'd add one to the int, convert back to a strin (don't forget to pad with leading zeros!), tack on the prefix, and you'd have“TEA0003” as your new value.
Thank you I will test it tomorrow and let you know as it’s 21:00 here.
Does knowing all of this just come with experience of epicor over the years or have you done training courses? I’d really like to be stronger in c#. I have the books and linq books slowly getting there.
Thank you Calvin. If I could buy you a beer I would.