- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-19-2021 12:06 PM
Hello all,
I have a requirement to remove the leading zeros from a string variable on a catalog item. The variable ('kronos_id_1') is populated using the onChange client script that follows. The employee_number may have up to five zeros preceding the number. Is there any way to remove them? It would not necessarily need to be onChange, as long as the result is that the zeros no longer appear after submission.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var name = g_form.getValue('name_1');
if (name != '') {
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id', name);
gr.query(function(gr) {
if (gr.next()) {
g_form.clearValue('kronos_id_1');
g_form.clearValue('email_address_1');
g_form.setValue('kronos_id_1', gr.employee_number);
g_form.setValue('email_address_1', gr.email);
g_form.setReadOnly('kronos_id_1', 'true');
g_form.setReadOnly('email_address_1', 'true');
}
});
} else {
g_form.clearValue('kronos_id_1');
g_form.clearValue('email_address_1');
}
}
Thank you in advance for any assistance you can provide.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-19-2021 12:24 PM
If you use parseInt() it will drop the leading zeroes as well. Converting it to an integer will just remove them which is all +num is doing.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-19-2021 12:19 PM
Thank you, Kieran.
Would I incorporate that in my current client script or would it be a separate onSubmit client script? Also, can you recommend a better way of accomplishing what I am trying to do without using a GlideRecord?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-19-2021 12:21 PM
You can use g_form.getReference() if it's a reference field.
g_form.getReference('field_name', functionName);
function functionName(response){
alert(response.field_name);
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-19-2021 12:24 PM
If you use parseInt() it will drop the leading zeroes as well. Converting it to an integer will just remove them which is all +num is doing.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-19-2021 12:43 PM
Absolutely - either + or parseInt() - doing the very same thing, just the first is for lazy people (well I obviously fit in this category 😄 ).
Cheers,
Joro
P.S. What