Serial No Generation Jscript CRM 2011
function Form_onload(){
function PadDigits(data, totalDigits, padChar)
{
data = data.toString();
var pad = '';
var dataLen = data.length;
if (totalDigits > dataLen)
{
for (i=0; i < (totalDigits-dataLen); i++)
{
pad += padChar;
}
}
return pad + data.toString();
}
Xrm.Page.getAttribute("numberlength").getValue()=8;
if (Xrm.Page.ui.getFormType() == 2)
{
if (Xrm.Page.getAttribute("currentnumber").getValue() == null)
{
Xrm.Page.getAttribute("currentnumber").getValue()=1000;
}
var prefix = Xrm.Page.getAttribute("prefix").getValue();
var separator = Xrm.Page.getAttribute("separator").getValue();
var currentno = Xrm.Page.getAttribute("currentnumber").getValue();
var serialno = prefix + separator + PadDigits(currentno,8,"0");
Xrm.Page.getAttribute("previewserialnumber").getValue()=serialno;
}
}