Hawk Posted March 17, 2016 Posted March 17, 2016 I'm getting this error on composition when I have a field name in my OnJobStart rule. "no data source defined or data could not be loaded" I does preview correctly. When I remove the field name it previews and composes correctly. This works var filename = 'CompanyName' + '.txt'; XDF = new ExternalDataFileEx("C:\\Shared\\130515_IdealSolutions\\" + filename, "\t"); return XDF.valid; This Does Not var filename = Field("ER.Name").replace(/ /g, '') + '.txt'; XDF = new ExternalDataFileEx("C:\\Shared\\130515_IdealSolutions\\" + filename, "\t"); return XDF.valid; Quote
Dan Korn Posted March 17, 2016 Posted March 17, 2016 I would add a line such as this before the "return" line in your rule: Print("XDF file name is: " + filename); Then compose and look at the log file and see what file name it's trying to open. My guess is that you don't want to simply remove every space in the field value for the file name. Quote
Hawk Posted March 17, 2016 Author Posted March 17, 2016 It seems that the OnJobStart rule will not run with a field in it. I cant get the filename variable to print. This is what I got; OnJobStart, line 2: Error: In Field(), no data source defined or data could not be loaded Job started 15:36:20 - 1458243380. Creator: FusionPro VDP Creator 8.2.5 Computer Name: HAWK-PC Current working folder: C:\Program Files\Common Files\Adobe\Adobe Version Cue CS4\Client\4.0.1 Template File: C:\Users\Hawk\Desktop\130515 Ideal Solutions\IRS Form 1095cCopy.pdf Input File: C:\Users\Hawk\Desktop\130515 Ideal Solutions\Printer PackardPart1&2.csv Rule Dependents, line 8: ReferenceError: XDF is not defined Rule Dependents Check Box, line 8: ReferenceError: XDF is not defined Composing record #1, input record 1 Sheet #1, record #1 Value for variable Rule Dependents not found in instance data Value for variable Rule Dependents Check Box not found in instance data Word <Dependents> does not fit in frame after line 1. The amount of text inserted into a flow exceeds the depth of all frames in the flow <(null)>. Text is truncated. Text does not fit in the last frame on page 1 at (7.37, 4.31). Job ended 15:36:23 - 1458243383. Quote
Dan Korn Posted March 17, 2016 Posted March 17, 2016 It seems that the OnJobStart rule will not run with a field in it. Sorry, I didn't notice before that you were in OnJobStart. Yes, it's true that you can't call the Field function in OnJobStart. This is because a data field value is specific to a particular data record, and at the time that OnJobStart is run, you don't yet have a record of data to process. (You could change to a completely different data source in OnJobStart, or decide to start on a different record than the first line in your data file.) The code should work in OnRecordStart. If you want to make sure that you're not opening the file more than once per job, you can do this: var filename = Field("ER.Name").replace(/ /g, '') + '.txt'; if (!XDF) XDF = new ExternalDataFileEx("C:\\Shared\\130515_IdealSoluti ons\\" + filename, "\t"); return XDF.valid; Or simply upgrade to FusionPro 9.3, where the XDFs are automatically cached, so that calling new ExternalDataFileEx repeatedly for the same file doesn't incur any penalty, so you can even open the file in a regular (non-callback) rule. Quote
step Posted March 17, 2016 Posted March 17, 2016 I'm pretty sure that's because the field values aren't accessible from OnJobStart. The "Field" function returns the value of a specified field for the current record but when OnJobStart is called, there is no current record. You could get around this by putting this in your OnRecordStart rule. It will only define the 'XDF' variable when it hasn't previously been defined. The result being that 'XDF' is only defined once much like if you were to call it from OnJobStart: var filename = Field("ER.Name").replace(/ /g, '') + '.txt'; if (typeof XDF == 'undefined') XDF = new ExternalDataFileEx("C:\\Shared\\130515_IdealSoluti ons\\" + filename, "\t"); Quote
step Posted March 17, 2016 Posted March 17, 2016 Woah, apparently I am too slow. Good thing repetition is the mother of learning, right? If you want to make sure that you're not opening the file more than once per job, you can do this: var filename = Field("ER.Name").replace(/ /g, '') + '.txt'; if ([color="Red"]!XDF[/color]) XDF = new ExternalDataFileEx("C:\\Shared\\130515_IdealSoluti ons\\" + filename, "\t"); return XDF.valid; I will say, though, I had originally written my code to be exactly like that but FP barked at me when I tried to validate. It seemed to me like you have to explicitly check whether a variable is defined. Or simply upgrade to FusionPro 9.3, where the XDFs are automatically cached, so that calling new ExternalDataFileEx repeatedly for the same file doesn't incur any penalty, so you can even open the file in a regular (non-callback) rule. Cool! I did not know that! Quote
Dan Korn Posted March 17, 2016 Posted March 17, 2016 Woah, apparently I am too slow. Good thing repetition is the mother of learning, right? Yep! We're both on top of things! I will say, though, I had originally written my code to be exactly like that but FP barked at me when I tried to validate. It seemed to me like you have to explicitly check whether a variable is defined. Unless you declare it in the JavaScript Globals; then it's a valid, declared variable whose value is void, which is admittedly a very subtle difference from a variable that's not declared at all. Quote
Recommended Posts
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.