Go Back   MarcomCentral (PTI) and FusionPro User Communities > Support > Issues, Questions, Etc.

Notices

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old January 27th, 2015, 08:37 AM
andym andym is offline
Junior Community Member
 
Join Date: Feb 2013
Posts: 21
Default Leading Zeros and Zip Code Formatting

I am referencing a list of addresses from an external data file. There are a few addresses in Massachusetts with leading zeros. Once the spreadsheet is put on MarcomCentral, the formatting defaults to drop leading zeros. The rule I wrote for this is below:

Code:
var Address = "";
var Name = "";
var Street = "";
var City = "";
var State = "";
var Zip = "";
var Country = "";
         
myXDF= new ExternalDataFileEx("ATLocations.txt", "\t");
 
for (i = 1; i < myXDF.recordCount+1; i++)
{
   FirstVar = myXDF.GetFieldValue(i, 0);
   {
        if (FirstVar==Field("Address"))
        {
            Name = myXDF.GetFieldValue(i, 1);
            Street = myXDF.GetFieldValue(i, 2);
            City = myXDF.GetFieldValue(i, 3);
            State = myXDF.GetFieldValue(i, 4);
            Zip = myXDF.GetFieldValue(i, 5);
            Country = myXDF.GetFieldValue(i, 6);
        }
    }
}
return ' | ' + City+", "+State+" "+FormatNumber("00000", Zip);
The last part of the returned text is the zip code. In previous templates this seemed to work for me, but I am now getting different results, i.e." MA, 1913 00000" where it drops the leading zero and puts five zeros after the actual zip code.

Finally, one extra item that we need to work. There are also Canadian addresses. Whatever rule(s) we use also needs to work for those locations. Now, the result looks like this: "Ontario, L6T 3V1 00000."

Is the rule I have on the right track? Should the zip code part be left out and made into an independent rule?

Any help is greatly appreciated.

Thank you,

Andy
Reply With Quote
  #2  
Old January 27th, 2015, 10:40 AM
Dan Korn's Avatar
Dan Korn Dan Korn is offline
FusionPro Senior Engineer / Forum Moderator
 
Join Date: Aug 2008
Location: Chicago, IL
Posts: 4,502
Default Re: Leading Zeros and Zip Code Formatting

Quote:
Originally Posted by andym View Post
The last part of the returned text is the zip code. In previous templates this seemed to work for me, but I am now getting different results, i.e." MA, 1913 00000" where it drops the leading zero and puts five zeros after the actual zip code.
This can happen if the second parameter to FormatNumber is actually a string, with non-numeric characters such as spaces. Try this instead on the last line:
Code:
return ' | ' + City + ", " + State + " " + FormatNumber("00000", Int(Zip));
Or:
Code:
return ' | ' + City + ", " + State + " " + FormatNumber("00000", Trim(Zip));
Quote:
Originally Posted by andym View Post
Finally, one extra item that we need to work. There are also Canadian addresses. Whatever rule(s) we use also needs to work for those locations. Now, the result looks like this: "Ontario, L6T 3V1 00000."
This is a horse (with a Mountie?) of a completely different color (colour?). You can't use FormatNumber on a Canadian Postal Code (not a "ZIP" code, that's USPS terminology), because, well, it's actually not a number at all.

If you Google for something like "Canadian Postal Code JavaScript validation," or "Canadian Postal Code JavaScript Regular Expression," you'll find some examples of JavaScript to validate and format these codes. Here's one: http://stackoverflow.com/a/26788801/3207828

Having said all of that, I think the third sentence in your post belies the real problem here:
Quote:
Originally Posted by andym View Post
Once the spreadsheet is put on MarcomCentral, the formatting defaults to drop leading zeros.
I assume that the "spreadsheet" to which you refer is an Excel document. Excel may indeed be The World's Most Popular Database (TM), but if it's mangling your data and you have to write rules in FusionPro to unmangle it, I would instead consider trying to manage your data in a different format that doesn't modify it in the first place.
__________________
Dan Korn
FusionPro Developer / JavaScript Guru / Forum Moderator
PTI Marketing Technologies | Printable | MarcomCentral
LinkedIn

I am a not a Support engineer, and this forum is not a substitute for Support. My participation on this forum is primarily as a fellow user (and a forum moderator). I am happy to provide help and answers to questions when I can; however, there is no guarantee that I, or anyone else on this forum, will be able to answer all questions or fix any problems. If I ask for files to clarify an issue, I might not be able to look at them personally. I am not able to answer private messages, emails, or phone calls unless they go through proper Support channels. Please direct any sales or pricing questions to your salesperson or inquiries@marcom.com.

Complex template-building questions, as well as all installation and font questions or problems, should be directed to FusionProSupport@marcom.com. Paid consulting work may be required to fulfill your template-building needs.

This is a publicly viewable forum. Please DO NOT post fonts, or other proprietary content, to this forum. Also, please DO NOT post any "live" data with real names, addresses, or any other personal, private, or confidential data.

Please include the specific versions of FusionPro, Acrobat, and your operating system in any problem reports or help requests. I recommend putting this information in your forum signature. Please also check your composition log (.msg) file for relevant error or warning messages.

Please post questions specific to the MarcomCentral Enterprise and Web-to-Print applications in the MarcomCentral forum. Click here to request access. Or contact your Business Relationship Manager (BRM/CPM) for assistance.

Please direct any questions specific to EFI's Digital StoreFront (DSF) to EFI support.

How To Ask Questions The Smart Way

The correct spellings are JavaScript, FusionPro, and MarcomCentral (each with two capital letters and no spaces). Acceptable abbreviations are JS, FP, and MC (or MCC). There is no "S" at the end of "Expression" or "Printable"! The name of the product is FusionPro, not "Fusion". "Java" is not is not the same as JavaScript.

Check out the JavaScript Guide and JavaScript Reference! FusionPro 8.0 and newer use JavaScript 1.7. Older versions use JavaScript 1.5.

return "KbwbTdsjqu!spdlt\"".replace(/./g,function(w){return String.fromCharCode(w.charCodeAt()-1)});
Reply With Quote
  #3  
Old January 27th, 2015, 11:18 AM
andym andym is offline
Junior Community Member
 
Join Date: Feb 2013
Posts: 21
Default Re: Leading Zeros and Zip Code Formatting

Thank you for your help Dan (and humor). The solution you listed for the leading zero worked perfectly.

As for the Canadian postal code, I found a work around to achieve my end goal and figured I would share here.

First I separated the Canadian address postal codes into their own column in Excel and updated the external data file on MarcomCentral. It now has seperate "Zip" and "PostalCode" fields. Then I duplicated the initial rule (from first post) and changed it so if the location is in Canada it will
Code:
return Rule("CANADA-Part 2");
else
return Rule("US-Part 2");
The only difference is the last line of the rule:

This is US-Part 2:
Code:
return ' | ' + City + ", " + State + " " + FormatNumber("00000", Trim(Zip));
This is CANADA-Part 2:
Code:
return ' | ' + City + ", " + State + " " + PostalCode + ' | ' + 'CANADA';
Thanks again,

Andy
Reply With Quote
  #4  
Old October 1st, 2020, 09:52 AM
ryanceot ryanceot is offline
Forum n00b
 
Join Date: Feb 2020
Posts: 2
Default Re: Leading Zeros and Zip Code Formatting

Hi Dan,

I'm in a similar situation (not zip code specific but leading zeros specific) but using external data. I have the current code, which is pulling the rec field instead of the "DITKT#" or "DDTKT#" fields. Any help is appreciated.

Thanks,
Ryan

//Calling data from an external data file
var ex = new ExternalDataFileEx('ppfinalfltb.csv', ',');
var cursor = ex.SortBy('KEY1');
var rec = cursor.FindRecords(Field('KEY1'));


if (((ex.GetFieldValue(rec, 'RDAT01') !='') && ex.GetFieldValue(rec,'DITKT#') != '') && (ex.GetFieldValue(rec,'DDTKT#') != ''))

{
return ex.GetFieldValue (rec, FormatNumber('0000000000000', Trim('DDTKT#'))) + ', ' + ex.GetFieldValue (rec, FormatNumber('0000000000000', Trim('DITKT#')));
}

if ((ex.GetFieldValue(rec,'RDAT01') !='') && (ex.GetFieldValue(rec,'DITKT#') != ''))

{
return ex.GetFieldValue (rec, FormatNumber('0000000000000', Trim('DDTKT#')));
}

if (ex.GetFieldValue(rec,'GROUND') !='')

{
return RawText('Our records indicate that have elected to make your own flight arrangements. Therefore, we do not have your ticket number(s) on file.');
}

return '';

Last edited by ryanceot; October 1st, 2020 at 09:56 AM..
Reply With Quote
  #5  
Old October 2nd, 2020, 10:57 AM
Dan Korn's Avatar
Dan Korn Dan Korn is offline
FusionPro Senior Engineer / Forum Moderator
 
Join Date: Aug 2008
Location: Chicago, IL
Posts: 4,502
Default Re: Leading Zeros and Zip Code Formatting

Quote:
Originally Posted by ryanceot View Post
I'm in a similar situation (not zip code specific but leading zeros specific) but using external data. I have the current code, which is pulling the rec field instead of the "DITKT#" or "DDTKT#" fields. Any help is appreciated.
Help with what exactly? What results are you getting, and how are they different from what you're expecting? Posting a sample of the data would be helpful.
__________________
Dan Korn
FusionPro Developer / JavaScript Guru / Forum Moderator
PTI Marketing Technologies | Printable | MarcomCentral
LinkedIn

I am a not a Support engineer, and this forum is not a substitute for Support. My participation on this forum is primarily as a fellow user (and a forum moderator). I am happy to provide help and answers to questions when I can; however, there is no guarantee that I, or anyone else on this forum, will be able to answer all questions or fix any problems. If I ask for files to clarify an issue, I might not be able to look at them personally. I am not able to answer private messages, emails, or phone calls unless they go through proper Support channels. Please direct any sales or pricing questions to your salesperson or inquiries@marcom.com.

Complex template-building questions, as well as all installation and font questions or problems, should be directed to FusionProSupport@marcom.com. Paid consulting work may be required to fulfill your template-building needs.

This is a publicly viewable forum. Please DO NOT post fonts, or other proprietary content, to this forum. Also, please DO NOT post any "live" data with real names, addresses, or any other personal, private, or confidential data.

Please include the specific versions of FusionPro, Acrobat, and your operating system in any problem reports or help requests. I recommend putting this information in your forum signature. Please also check your composition log (.msg) file for relevant error or warning messages.

Please post questions specific to the MarcomCentral Enterprise and Web-to-Print applications in the MarcomCentral forum. Click here to request access. Or contact your Business Relationship Manager (BRM/CPM) for assistance.

Please direct any questions specific to EFI's Digital StoreFront (DSF) to EFI support.

How To Ask Questions The Smart Way

The correct spellings are JavaScript, FusionPro, and MarcomCentral (each with two capital letters and no spaces). Acceptable abbreviations are JS, FP, and MC (or MCC). There is no "S" at the end of "Expression" or "Printable"! The name of the product is FusionPro, not "Fusion". "Java" is not is not the same as JavaScript.

Check out the JavaScript Guide and JavaScript Reference! FusionPro 8.0 and newer use JavaScript 1.7. Older versions use JavaScript 1.5.

return "KbwbTdsjqu!spdlt\"".replace(/./g,function(w){return String.fromCharCode(w.charCodeAt()-1)});
Reply With Quote
Reply

Tags
code, formatting, leading zero, zip

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 07:44 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
(c) 2011, PTI Marketing Technologies™, Inc.