Jump to content

Can inputFileName be tested in (non callback) JS rule?


esmith

Recommended Posts

I was hoping to be able to create a rule that would return a different result based on the particular input data file. Is it possible to test this information in a text/graphic rule?

 

For example:

return (FusionPro.Composition.inputFileName() == "sample.txt") ? *do this* : *DO THIS*;

Link to comment
Share on other sites

  • 3 weeks later...

Any answers from the men behind the curtain? The latest desire is to be able to set BodyPageUsage based on inputFileName, in this case used in an OnJobStart rule.

 

Can FP retrieve the current input file's name through JS?

Link to comment
Share on other sites

Sure, not much to it really. Just assign it to a variable and then run whatever tests on it.

var fileName = FusionPro.Composition.inputFileName;
return (fileName.match(/testpattern/)) ? "good" : "bad";
// OR if you aren't using RegEx
return (fileName.indexOf("testpattern")>-1) ? "good" : "bad";

In preview mode and in the code editor window you'll always get an error or sometimes even an erroneous result. You'll get correct results when composing though. Also note the inputFileName is a property of the Composition object, so the JS engine will complain if you put parentheses on the end of it.

 

EDIT: looking at the JS String object, I see you can use the match() method even with string matching (non-RegEx). I never knew that as I've always used it with RegEx. Learned something new.

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...