ThePorge Posted November 12, 2020 Share Posted November 12, 2020 I'm trying to extract a job number from my input file name. This is in the OnRecordStart Rule. var inputName = FusionPro.Composition.inputFileName; //In this instance the file name is "140583_Combo.xls" inputName = inputName.match(/^\d+/); if (FieldChanged("CredFmType")) { FusionPro.Composition.OpenNewOutputFile(inputName + "_" + Field("CredFmType") + "." + FusionPro.Composition.outputFormatExtension); } This outputs the pdfs with null where the job number should be. If I replace var inputName = FusionPro.Composition.inputFileName; with var inputName = "140583_Combo.xls"; It works fantastically. I'm sure I'm overlooking something, but I can't seem to figure it out. Any help out there? Tks in advance! Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted November 12, 2020 Share Posted November 12, 2020 In cases like this, I try to make sure I know exactly what the input parameters are. In this case, you need to make sure you understand the format of the string you're applying the match function to, which is FusionPro.Composition.inputFileName. The best way to determine what that value is, is empirically, via direct examination. So, if you either create a rule to return FusionPro.Composition.inputFileName, and put that into a text frame and look in the output, or make a rule like this, compose, and then look in the log file: Print("FusionPro.Composition.inputFileName: " + FusionPro.Composition.inputFileName); You will see that it's not just the file name, as your hard-coded test assumes; it's actually the entire full path to the file, with the folder path as well as the file name. This process, of empirically examining the values of variables at different points in the flow of a program or function, is what we programmers call debugging. If you want just the file name part of the path, you can call the GetFileName function. So I think the rule will do what you want if you change the first line to this: var inputName = GetFileName(FusionPro.Composition.inputFileName); Or, a bit more robustly, to work in Preview and rule validation as well as composition: var inputName = GetFileName(PrimaryInputFile()); Quote Link to comment Share on other sites More sharing options...
ThePorge Posted November 13, 2020 Author Share Posted November 13, 2020 I guess I was thrown off as I thought I was testing the output. I had commented out the match to see the result for the sole purpose of seeing exactly what I was working with. Only the input file name showed up in my output file's name and not the whole path. Conversely, I did as you said and put the result into a text box and it did contain the whole path. That seems to confuse me a bit as I seem to be getting different results. Is there something I am missing here? Thanks for you help btw and the var inputName = GetFileName(FusionPro.Composition.inputFileName); works great! Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted November 13, 2020 Share Posted November 13, 2020 I guess I was thrown off as I thought I was testing the output. I had commented out the match to see the result for the sole purpose of seeing exactly what I was working with. Only the input file name showed up in my output file's name and not the whole path. I'm not sure what you mean. The output file has a full path associated with it, not just a file name. You can pass either a full path or just a file name to the FusionPro.Composition.OpenNewOutputFile function. If you pass just a name, it will use the same path as the original output file. If you pass a full path, it will use that full path. Conversely, I did as you said and put the result into a text box and it did contain the whole path. That seems to confuse me a bit as I seem to be getting different results. Is there something I am missing here? Presumably your input and output files are already pointing to the same folder, which is why setting the full path to use the input path didn't change the output path. But I can only guess at what the actual file paths and names are from what you've provided. Thanks for you help btw and the works great! Glad to help! Quote Link to comment Share on other sites More sharing options...
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.