Can I pad a value before insert from record producer?

eptnavyguy
Tera Contributor

I have a requirement that a value be a specific length when inserted on the form from a record producer, without making the user meet the requirement. I've attempted an onSubmit Client Script but it isn't working.  The variable is a string.

 

   var hours = g_form.getValue('variable').length;
   var size = 10;
   while (hours < size){
   hours = "0" + hours;
   }
   g_form.setValue('variable', hours);

 

 

2 REPLIES 2

Ahmmed Ali
Mega Sage

Hello @eptnavyguy 

 

You are adding 0 to length, not the variable value. try below script: 

 

 

var hoursValue = g_form.getValue('variable');

   var size = 10;
   while (hoursValue.length < size){
   hoursValue = "0" + hoursValue;
   }
   g_form.setValue('variable', hoursValue);

 

 

You can try this script in onchange script as well. which will make user also know about this.

 

Thank you,

Ali

If I could help you with your Query then, please hit the Thumb Icon and mark my answer as Correct!!

Thank you,
Ali

Unfortunately, that didn't work. I appreciate your help.