logo

NJP

script: padleft function - Pad a number to two, three, four digits with Javascript

Import · Dec 05, 2018 · article

script: padleft function - Pad a number to two, three, four digits with Javascript

Como preencher um número com zeros à esquerda

Como rellenar con ceros a la izquierda

function padleft(strPad, intSize)
{
var s = String(strPad);
while (s.length < (intSize|| 2)) {s = "0" + s;}
return s;
}
var objQ = new GlideRecord("table");
objQ.query();

while(objQ.next())
{
if (objQ.field.toString().length <= 3)
{
//gs.debug(padleft(objQ.field.toString(), 4));
objQ.field= padleft(objQ.field.toString(), 4);
objQ.update();
}
}

image

Update set Planejando e executando mudanças no ambiente.

Was useful, please leave your feedback!

View original source

https://www.servicenow.com/community/itsm-articles/script-padleft-function-pad-a-number-to-two-three-four-digits/ta-p/2305732