Sometimes we need to add padding numbers in the files in AX. Ex: Postive pay files
I found the below post that helped to add the padding zero numbers in the positive pay file.
Original post: http://www.atomicax.com/content/zero-padding-numbers
AX provides us with an easy way to pad strings with extra characters. A common situation where this is required is use a "fake" number sequence inside AX.
If you wish to increment a counter, but store or display it as a string such as "ABC-00001", "ABC-00002" etc then padding the counter with zeros is required.
We can use the strRFix() and strLFix() methods to achieve this.
static void testZeroPadding(Args _args)
{
int i = 1;
str padded;
str finalResult;
;
// Create a string, with a length of 5, ending with the value of i and padded with zeros
padded = strRFix(int2str(i), 5, "0");
finalResult = strFmt("ABC-%1", padded);
}This will populate finalResult with ABC-00001. If we use strLFix instead of strRFix, it will pad to the right with zeros, giving us ABC-10000.
Alternatively, you could use a function like this: (However, the approach above is most likely faster)
static str zeroPad(str item, int numZero)
{
int i;
str out;
;
for(i=0;i<numZero-strlen(item); i++)
{
out += "0";
}
return(out + item);
}
You should take help from professionals who have immense experience on Dynamics 365 finance. They will help you with Solutions easily. Learn: Dynamics 365 finance and operation
ReplyDeleteUse strPadLeft(int2str(number), desiredLength, '0')webspacekit to apply zero padding to numbers in D365 F&O X++.
ReplyDelete