Jump to content

JavaScript Globals not returned during Composition


Recommended Posts

Posted

I'm having an issue where when I set a Global Variable in JavaScript Globals, say:

 

GLOBAL_path_Root =(FusionPro.isMac ? "/Volumes/DL/" : "D:/DL/");

 

And then I create a Graphic Rule "test_r":

return CreateResource(GLOBAL_path_Root+"x.pdf" , "Graphic" , true);

 

During Composition, I get this error:

test_r, line 1: ReferenceError: GLOBAL_path_Root is not defined

 

If I open the Javascript Globals, and the open the Rule, the Rule Validates OK. If I close the Rules Editor and go back into it, if I edit the Rule without first opening Javascript Globals, I get a dialog that gives the same error.

 

What am I doing wrong? FPDesktop 7.2P1K under Mac OS 10.6 & Acrobat X

Posted

Problem turns out to be the following: you cannot mention Field('fieldname') in Javascript Globals. Doing so manages to invalidate any variables declared after the assignation of Field() to any variable.

 

Understandably, FP is disallowing references to fields in the Global scope (even if one only requires the field from the first record). However, FP doesn't throw up any errors upon exiting Javascript Globals. Worse, in the documentation, in the section that discusses Javascript Globals, there is explicit reference to defining a global var using a field reference.

 

Any rules edited immediately after viewing Javascript Globals dialog validate properly with any global vars that reference a field. However, closing out of the Rules Editor and either Composing or re-entering the Rules Editor without first visiting Javascript Globals will produce ReferenceErrors where your global variable is "not defined".

Posted

Yes, the documentation is misleading. Sorry about that.

 

What are you trying to do with a record-specific data field value in JavaScript Globals or in OnJobStart? Whatever it is, there's probably a better way to do it.

 

Note that you can define a function in JavaScript Globals which calls the Field function, and then call your function in other rules. You can also declare a global variable in JavaScript Globals and set it in another rule such as OnRecordStart, and it will be available to all other rules.

 

Finally, why are you setting that global variable to define the path at all? You should just be able to add "/Volumes/DL/;D:/DL/" to the Search Path on the Advanced tab of the Composition Settings dialog, and then you can call CreateResource without the path on either platform. Or just put the resources in the same folder as the template.

Posted

Hi Dan,

 

The data that I'm trying to pull into Javascript Globalss or OnJobStart happens to be data that's the same for every record in the data file. I used to have Rules returning GLOBAL_PathThis and GLOBAL_PathThat, but these get called on every record composition. I'm trying to use Jgs or OnJobStart because they only get called once, which just seems a more efficient way to go.

 

It's true I could use the Search Path, however, that Root is just the tip of the iceberg for a lot of stuff. I have lots and lots of subdirectories with thousands, sometimes tens of thousands of resources each. From one job to the next, resource directories will change. Seems more efficient to build paths programmatically, and everything is managed.

 

So it's Job specific, but "global" to the current composition. Declaring paths globally, simply give me flexibility which happens occasionally when I migrate from one Server machine to another. It's easier for me to update one Rule like OnJobStart, than go into multiple Graphic Rules to update the way they are building paths to CreateResource.

 

I'm currently trying to pull the information I need out of the input filename. But it sounds like I may have to go back to using Rules, called on every record.

Posted
Hi Dan,

 

The data that I'm trying to pull into Javascript Globalss or OnJobStart happens to be data that's the same for every record in the data file. I used to have Rules returning GLOBAL_PathThis and GLOBAL_PathThat, but these get called on every record composition. I'm trying to use Jgs or OnJobStart because they only get called once, which just seems a more efficient way to go.

 

It's true I could use the Search Path, however, that Root is just the tip of the iceberg for a lot of stuff. I have lots and lots of subdirectories with thousands, sometimes tens of thousands of resources each. From one job to the next, resource directories will change. Seems more efficient to build paths programmatically, and everything is managed.

 

So it's Job specific, but "global" to the current composition. Declaring paths globally, simply give me flexibility which happens occasionally when I migrate from one Server machine to another. It's easier for me to update one Rule like OnJobStart, than go into multiple Graphic Rules to update the way they are building paths to CreateResource.

 

I'm currently trying to pull the information I need out of the input filename. But it sounds like I may have to go back to using Rules, called on every record.

What I would recommend here is creating a secondary data file with the truly "global" data, including the paths specific to each run. The you can use ExternalDataFileEx to read this file in OnJobStart to set things up. If you do this right, you can make the job work on any system, including in FP Server, just by modifying or supplying a new secondary file, without having to open up the job in FP Desktop and modify the rules every time to migrate to another server.

 

The other option, if you're using FP Server for composition, is to add custom entries to the CFG file, and access them with the FusionPro.Composition.JobOptions object. For instance, if you add a line to the CFG file such as "GLOBAL_path_Root=/Volumes/DL", then you can access this as FusionPro.Composition.JobOptions["GLOBAL_path_Root"] in any rule.

Posted
Note that you can define a function in JavaScript Globals which calls the Field function, and then call your function in other rules.

 

This unfortunately does not seem to work anymore in MarcomCentral. It returns the rule name instead. The only way to get around it is to pass the Field value to the global function. I'm wondering what happened because it used to work fine. I'm having to redo all the templates that used that method.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...