Announcing the Global SNUG Board of Directors. Learn more here

Help
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
tiagomacul
Mega Sage
Mega Sage

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();
}
}

 

 

Know-More-Now-Logo.jpg

Update set Planejando e executando mudanças no ambiente.

 

 

Was useful, please leave your feedback!

Comments
tiagomacul
Mega Sage
Mega Sage

 

var grRec = new GlideRecord("incident");
grRec.setLimit(10);
grRec.query();
while (grRec.next()) {
      gs.print('test: ' + grRec.number.getDisplayValue().substring(0, 3));
}
Version history
Last update:
‎12-05-2018 04:57 AM
Updated by: