Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

tiagomacul
Giga 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
Giga 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: