Go Back   MarcomCentral (PTI) and FusionPro User Communities > Software-Related Talk > The JavaScript Library

Notices

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old July 6th, 2022, 11:35 AM
ReminderVDP ReminderVDP is offline
Regular Contributor
 
Join Date: Jan 2013
Location: King of Prussia, PA
Posts: 138
Default Reg Ex or Javascript for File Name

I've got a rule in a file that looks for a PDF on a server in a folder based on the file name. It's looking for the file based on a field in my data but I'm adding two zeros in the rule because the data field does not contain the zeros.

For example, the data field has "9" in it. The file it is looking for has "009" in it. My current rule is this:
Code:
var issueNumber = 'GH00' + Field("MagIDShort");

var pathName = "X:\\EDITORIAL\\FinalGutsforProofs\\GHM\\";
var FullResourcePath = pathName + issueNumber + "\\" + 'GH_magazine-00' + Field("MagIDShort") + ".pdf"; //change to match your data file field
var x = new FusionProResource(FullResourcePath, "graphic", 1);
if (!x.exists)
ReportError("Graphic not found: " + FullResourcePath);
var pdfString = '';
var pages = (x.countPages);
for (var pgnbr = 1; pgnbr <= pages; pgnbr++)
{
x.pagenumber = pgnbr;
pdfString += x.value + '<p>\n';
}
Print("Result is: " + pdfString);
return pdfString;
It adds the two zeros in line 4. However, we are coming up on issue 10 so I will only need to add one zero to the rule, but I still have people making files looking for issue 9 and still need the two zeros in the file name.

Is there some reg ex that would look for one or two zeros? I'm not good at reg ex so I'm looking for a solution that can be used for either file name, 009 or 010. Thanks in advance.
__________________
Bryan Mathes, Print Production Specialist
FusionPro Designer 10.1.11, FusionPro Producer (Server) API 10.1.11
Mac OSX 10.12.6
Mac Pro 2.8 GHz Quad Core Intel Xeon
Reply With Quote
  #2  
Old July 6th, 2022, 03:36 PM
ThomasLewis's Avatar
ThomasLewis ThomasLewis is offline
Senior Contributor
 
Join Date: Feb 2011
Posts: 233
Default Re: Reg Ex or Javascript for File Name

I think what you are looking for is the FormatNumber function
FormatNumber("000", inputNumber)
Reply With Quote
  #3  
Old July 6th, 2022, 03:46 PM
ReminderVDP ReminderVDP is offline
Regular Contributor
 
Join Date: Jan 2013
Location: King of Prussia, PA
Posts: 138
Default Re: Reg Ex or Javascript for File Name

Thomas,
Would that go in place of the 00 in the code below?

Code:
+ 'GH_magazine-00'
__________________
Bryan Mathes, Print Production Specialist
FusionPro Designer 10.1.11, FusionPro Producer (Server) API 10.1.11
Mac OSX 10.12.6
Mac Pro 2.8 GHz Quad Core Intel Xeon
Reply With Quote
  #4  
Old July 6th, 2022, 04:12 PM
ThomasLewis's Avatar
ThomasLewis ThomasLewis is offline
Senior Contributor
 
Join Date: Feb 2011
Posts: 233
Default Re: Reg Ex or Javascript for File Name

Like this if I'm reading your code right:

Code:
... "\\" + 'GH_magazine-' + FormatNumber("000", Field("MagIDShort")) + ".pdf";
Reply With Quote
  #5  
Old July 7th, 2022, 07:53 AM
ReminderVDP ReminderVDP is offline
Regular Contributor
 
Join Date: Jan 2013
Location: King of Prussia, PA
Posts: 138
Default Re: Reg Ex or Javascript for File Name

That's what I thought you meant. I will try that. Thanks!
__________________
Bryan Mathes, Print Production Specialist
FusionPro Designer 10.1.11, FusionPro Producer (Server) API 10.1.11
Mac OSX 10.12.6
Mac Pro 2.8 GHz Quad Core Intel Xeon
Reply With Quote
  #6  
Old July 7th, 2022, 11:43 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,671
Default Re: Reg Ex or Javascript for File Name

If you want to test for multiple possibilities, you can do that in a loop, something like this:
Code:
var x;
for (var zeros = 0; zeros <= 3; zeros++)
{
    var issueNumPadded = new Array((zeros || 0) + 1).join("0") + issueNumber;
    var FullResourcePath = pathName + issueNumber + "\\" + 'GH_magazine-' + issueNumPadded + ".pdf";
    x = new FusionProResource(FullResourcePath, "graphic", 1);
    if (x.exists)
        break;
}
if (!x || !x.exists)
    ReportError("Graphic not found for " + issueNumber);
__________________
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
  #7  
Old July 20th, 2022, 02:31 PM
ReminderVDP ReminderVDP is offline
Regular Contributor
 
Join Date: Jan 2013
Location: King of Prussia, PA
Posts: 138
Default Re: Reg Ex or Javascript for File Name

Thanks Dan. I did get it to work with the code ThomasLewis put in here. That was a huge help.
__________________
Bryan Mathes, Print Production Specialist
FusionPro Designer 10.1.11, FusionPro Producer (Server) API 10.1.11
Mac OSX 10.12.6
Mac Pro 2.8 GHz Quad Core Intel Xeon
Reply With Quote
Reply

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 04:06 PM.


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