Jump to content

Unique Number Persistent Over Multiple Jobs


Recommended Posts

Being asked if there is any way to have a unique number sequence in FusionPro Creator that "remembers" where it left off over all jobs that are run.

 

Desire is to have unique numbers for all documents produced by the facility, trying to replace a system that generated a 7-digit number that didn't repeat for 10 years.

 

I asked about doing this on the database side, but the customer said they are not able to do it.

 

Any experiences or advice appreciated.

Edited by invaricconsulting
Link to comment
Share on other sites

Yes, usually this kind of thing is handled outside of the context of FusionPro, generally by an application which feeds data to FusionPro VDP Producer API (FP Server) as part of a larger system. FusionPro itself doesn't "persist" or "remember" anything between composition runs.

 

That said, I can think of a couple of things that you might be able to get working. One idea is to have FusionPro write a message to the log file by calling the Print() function, or to an XML log file by calling FusionPro.Composition.LogXMLMetadata(), then read in that log file again as an External Data File and search/parse it for the message written by the last composition run. This would require a bit of JavaScript coding.

 

Another approach is to base the number on UNIX time, which is very easy to obtain with JavaScript, like so:

// Current UNIX time (number of seconds since 1 January 1970 00:00:00 UTC).
return parseInt(new Date().getTime() / 1000, 10);

That is pretty much guaranteed to return a unique 10-digit decimal number (at least for the next 30 years or so, after which it will return 11 digits).

 

But if the customer really only wants seven unique digits, you can probably safely trim off the last three, which will result in a seven-digit number that changes every 16 minutes or so (every 1000 seconds), like so:

return String(parseInt(new Date().getTime() / 1000, 10)).substr(0, 7);

Link to comment
Share on other sites

It sure helps when going down a path to know it's a viable one. I took your xml log file suggestion Dan, and it works great. What the JavaScript code does...

 

- In OnJobEnd, creates xml log file using FusionPro.Composition.CreateXMLLogFile(), writes a new key/value for the sequence number to the log file using FusionPro.Composition.LogXMLMetadata()

 

- In OnJobStart, reads xml log file as external data file using ExternalDataFileEx(), searches/parses for key generated by OnJobEnd, gets current value

 

- In OnRecordStart, increments the sequence value for however many records are in the current job

 

^Back to OnJobEnd to write the new sequence number to the xml log file, and so on for each new job that is run...

 

End result is 7-digit number consisting of, last digit of current year, current month as an alpha character from A to L, then 5-digit sequence number per the above, which in this case increments up to 99999, then resets back to 00001 via OnRecordStart.

 

Thanks Dan.

Link to comment
Share on other sites

  • 2 months later...

I am experiencing a challenge with this CreateXMLLogFile method. The XML log file is getting saved to different folder locations. I think it might be based on the folder location where I last saved a PDF.

 

Anyway, is there any way to control where the XML file gets saved? It appears that specifying a subdirectory in-line like this:

 

FusionPro.Composition.CreateXMLLogFile("\Compose\LabelFormSeqNum.xml");

 

...does not do the trick.

Edited by invaricconsulting
Link to comment
Share on other sites

I am experiencing a challenge with this CreateXMLLogFile method. The XML log file is getting saved to different folder locations. I think it might be based on the folder location where I last saved a PDF.

Actually, a relative path is resolved based on the current working folder. If you're composing in Acrobat (Desktop), the current working folder is set by the application, and is not necessarily visible to the user.

 

This XML Log File feature was originally intended to be used with a CFG file setting with the command-line composition engine, and was also intended to use a fully-qualified path specification.

Anyway, is there any way to control where the XML file gets saved?

Sure, use a fully-qualified (absolute) path.

It appears that specifying a subdirectory in-line like this:

 

FusionPro.Composition.CreateXMLLogFile("\Compose\LabelFormSeqNum.xml");

 

...does not do the trick.

Well, for one, you're making a very common error with JavaScript. The backslash '\' character in a string denotes an escape. Since '\C' and '\L' are not valid escapes, the backslashes are ignored, so you're really trying to make a file named "ComposeLabelFormSeqNum.xml" in the current working directory. (You can see this if you return the literal string you're using in the function call.)

 

If you want a literal backslash in a string, you have to use two backslashes, like so:

FusionPro.Composition.CreateXMLLogFile("\\Compose\\LabelFormSeqNum.xml");

Although, on Windows, you can use forward slashes instead, which work exactly the same way in the file system (except at the start of a UNC path), but don't need to be escaped in JavaScript strings:

FusionPro.Composition.CreateXMLLogFile("/Compose/LabelFormSeqNum.xml");

The other advantage of using forward slashes is that your rule should work pretty much the same way on both Windows and Mac.

 

As for specifying a relative path (a subdirectory), that doesn't work (or at least it's not always obvious what the current working folder is). So you need to use a fully-qualified, absolute path.

 

You can specify the path to be relative to another path, such as the output file path, like so:

FusionPro.Composition.CreateXMLLogFile(FusionPro.Composition.outputFileFullPathName + "/../Compose/LabelFormSeqNum.xml");

Although, however you specify the path, the folder has to exist and be writable.

 

You may also want to test the return code of the FusionPro.Composition.CreateXMLLogFile function, like so:

if (!FusionPro.Composition.CreateXMLLogFile(FusionPro.Composition.outputFileFullPathName + "/../Compose/LabelFormSeqNum.xml"))
   throw "Unable to open XML Log File!";

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...