4 Replies Latest reply: Feb 14, 2012 8:08 AM by Marcos J Pinto RSS

    How do I name output files based on files processed from a watched folder?

    Marcos J Pinto Community Member

      Hello!

       

      I've built a small process to merge XML files with XDP templates, generating PDF files at the end of the process.

       

      Right now the process is generating all files with a fixed name + a random number, as defined in the Input panel (literal value with option "Appen a suffix..." checked.

       

      I'd like to change this so the resulting files have the same name as the input files, changing only the extension (PDF instead of XML).

       

      I believe I should change from literal value to XPath expression, in order to build the resulting name based on the input file name.

       

      QUESTION: what function should I use to get the input file name in XPath builder (if this is the right place to do it) ?

       

      I tried with:

       

           getDocAttribute(/process_data/@docApolicesXML,"wsfilename")  + ".PDF"

       

      Does not work.

       

      Thanks a lot for any hints!

       

      Marcos

        • 1. Re: How do I name output files based on files processed from a watched folder?
          kc@dafolo.dk Community Member

          Hi Marcos,

           

          You should do the following:

           

          Create new variable "filename"

           

          And in a Set value you should:

           

          filename = getDocAttribute(/process_data/@docApolicesXML,"basename")

          filename = concat(/process_data/@filename,".pdf")

           

          This will give you "myFile.xml.pdf - if you want myFile.pdf instead, you need to do this in the Set value:

           

          filename = getDocAttribute(/process_data/@docApolicesXML,"basename")

          filename = substring-before(/process_data/@filename,".xml")

          filename = concat(/process_data/@filename,".pdf")


          That should do it :-)

           

          Kim Christensen

          Dafolo A/S

          Denmark


          • 2. Re: How do I name output files based on files processed from a watched folder?
            Marcos J Pinto Community Member

            Hi Kim,

             

            Thank you so much for the info!

             

            Now, I'm doing something wrong... can't figure out what...

            So I added a SetValue task to build the file name using your code.

            Then, in the Write Document task, I set the Pathname Pattern as a XPath Expression using this expression:

             

                 concat("C:\Users\marcosp\Documents\NetBeansProjects\ConversorDAT_XML\dist\monitorada\PDF\ ", /process_data/@fileName)

             

            I get a failure saying it was not possible to overwrite file - it's getting the path part of the concat function but nothing from @fileName.

             

            If I replace the variable reference with a string (say, "myfile.pdf"), it works, but with the fixed name.

             

            Please, help! 

             

            Marcos

            • 3. Re: How do I name output files based on files processed from a watched folder?
              kc@dafolo.dk Community Member

              Hi again Marcos,

               

              OK - try to do your concat of the path within a "Set value" step instead, so you have to create another variable "absoluteFilePath" and do your concat.

               

              absoluteFilePath = concat("C:\Users\marcosp\Documents\NetBeansProjects\ConversorDAT_XML\ dist\monitorada\PDF\", /process_data/@fileName)

               

              Then you set your absoluteFilePath variable as the varible your need for the WriteToDisc service.

               

              Also try to enable recording to see what value your fileName actually has.

               

              Hope this helps

               

              Cheers

              Kim Christensen

              Dafolo A/S

              Denmark

              • 4. Re: How do I name output files based on files processed from a watched folder?
                Marcos J Pinto Community Member

                Hi again Kim,

                 

                Now it's working!! Thank you so much for the help!

                 

                I didn't have to use the new variable; you helped me again by suggesting I enabled recording to check variable values - the filename variable wasn't being set for a very simple reason: the SeValue task was not being executed because I had  dragged it over the route line and hadn't noticed it was not connected... once I corrected this, voilà, it's doing its job perfectly.

                 

                Thank you so much!!

                 

                Greetings from Brazil.

                 

                Marcos

                 

                Just an update: I was having problems setting the variable with those three lines (probably some mistake of mine) so I got it working nesting everything like this:

                 

                          concat(substring-before(getDocAttribute(/process_data/@docApolicesXML, "basename"), ".xml"), ".pdf")

                 

                Cheers.

                 

                Marcos