- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2017 02:08 PM
Hi all
I am currently able to strip a store number from an inbound email. Trouble I have is that they could be, 1 digit, 2 digit, 3 digits or 4. The email I receive leaves out the leading zeros and I hold them as 4 digits (with the leading zeros). E.g, Inbound email has "1" whereas I hold "0001". My code is:
var store=email.body_text.split('\n');
for(i=0; i<store.length; i++){
if(store[i].indexOf('Store Epos:')>-1) {
var storeIs = (store[i].trim().split(':')[1].trim());
gs.info('RCC Inbound Store is = ' + storeIs);
current.store_number = storeIs;
Any ideas on how to add in the leading zeros?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2017 07:29 PM
Hi Steven,
Try this to pad your store number within your script:
//Pad the value of storeIs to ensure it is 4-digits
for(i = storeIs.length;i < 4;i ++){
storeIs = '0' + storeIs;
}
That should work for you. I ran into the same issue with an old Employee Number field, this was my solution. Let us know if you still have any issue.
Thanks,
-Brian
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2017 03:45 PM
Sorry but i didnt get your question, you mean your inbound mail contains Store Epos:1 but by using the above code you get 0001 , is it?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2017 04:28 PM
Hi Deepa
Yes, it would need to be 0001 for a 1 digit number, 0021 for 2 digit, 0212 for the 3 digit number.
Steve

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2017 07:29 PM
Hi Steven,
Try this to pad your store number within your script:
//Pad the value of storeIs to ensure it is 4-digits
for(i = storeIs.length;i < 4;i ++){
storeIs = '0' + storeIs;
}
That should work for you. I ran into the same issue with an old Employee Number field, this was my solution. Let us know if you still have any issue.
Thanks,
-Brian
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2017 04:23 AM
Thanks Brian. Worked like a treat.