There are many times when we want to create a unique Serial number/ Code to use in Ax, The following job uses standard ax functions to create a serial number.
static void GenerateLicensekey(Args _args)
{
str LicenceKey;
int iConLen;
int i,largestStr, conStrLength, j, pos;
container
c;
//returns a char from the string
str getLicenceChar(str _fromStr, int
position)
{
return subStr(_fromStr,
position,1);
}
c = ['1005','SER_','9001','1808'];
iConLen = conLen(c);
largestStr= strLen(conPeek(c,1));
//get largest string
for(i =2;
i <= iConLen; i++)
{
conStrLength = strLen(conPeek(c,i));
if( conStrLength > largestStr)
{
largestStr= conStrLength;
}
}
//perform licence key generation
for (i=1;
i<=largestStr; i++)
{
pos++;
for(j=1;
j<=iConLen; j++)
{
if(pos <= strLen(conPeek(c,j)))
{
LicenceKey += getLicenceChar(conPeek(c,j),pos);
}
else
{
continue;
}
}
}
info(LicenceKey);
}
No comments:
Post a Comment