14 Replies Latest reply on Nov 1, 2018 7:22 PM by darcyc

    How to define destination file name when generated report?

    david_zhou

      for Masshunter

      after generated report, report file name = "destination file"_"Sequence No"_"Data File(remove .D)", lile below:

      I hope update report file name = "destination file"_"Sequence No"_"Name"_"YYYYMMDDHHMMSS(report generated date time)"

      is it possible?

       

        • Re: How to define destination file name when generated report?
          ryoboyle

          Hello,

           

          I updated the tags on this post to increase visibility.

           

          There is no way to change how the pdf report files are named from the software's GUI beyond the destination file name that can be specified in the report method. The rest of the naming pattern is hard-coded in the software. Renaming the report files could potentially be handled in a post process script, but that would require application consulting from Agilent if you would like one to be developed for you.

            • Re: How to define destination file name when generated report?
              david_zhou

              Hi ryoboyle:

              thank you for your professional suggestion.

              Can I apply to you developed post process script base on "QuantReportPostProcess-CopyCSVFile.bat " ?

              renaming the report files, add files created date time(_YYYYMMDDHHMMSS),

              like below:Gen_ResultsSummary_021_CAN17-185559_001_20180627154909

                • Re: How to define destination file name when generated report?
                  ryoboyle

                  Hi David,

                   

                  I received confirmation that adding a date and time stamp to the end of a report file would be possible through editing Python code in Quant. This would be a custom modification of the software and you would need to contact your local Agilent support (Contact Us | Agilent ) to request this.

                   

                  There is one very minor caveat. The reporting process has a feature to open the published file when complete. That feature no longer works as it doesn’t know the file name has been changed.

                    • Re: How to define destination file name when generated report?
                      david_zhou

                      Hi ryoboyle:

                      we use report template is created by ReportBuilder

                      is it possible adding a date and time stamp to the end of report file name?

                      please advise what can i do?

                        • Re: How to define destination file name when generated report?
                          ryoboyle

                          David,

                           

                          I can only repeat the recommendation I gave you in my previous reply. This would be a custom modification of the software and you would need to contact your local Agilent support (Contact Us | Agilent ) to request this.

                           

                          This is an open community so it is possible another user might be able to chime in with other recommendations, but if this is an urgent matter then contacting support would be the best course of action.

                          • Re: How to define destination file name when generated report?
                            darcyc

                            Decided to have a crack at this, seemed like a good mini project that I hadn't thought to do with our own reports.

                             

                            You've referenced a .bat script so I assume some passing familiarity here but for those who might not be as familiar I'll Go in some detail  step by step.

                             

                            I decide to go with a vbs script rather than .bat but otherwise the same idea. Here we go...

                             

                            1. Create a new text file in Explorer for your script. Rename the file from "New Text Document.txt" to something like "Rename_script.vbs" the file extension is important here. If you can't see file extensions by default then change that setting in Explorer so you can change it. You'll get an "Are you sure" type message when you change the extension, just hit "Yes".

                             

                            2. Open your new script by right clicking and selecting "Edit" don't double click the file to open, that runs scripts and your's is empty at this point, it will do nothing.

                             

                            3. Paste in the following (I'll tell you how to edit it to meet your needs later:

                             

                            Set FSO = CreateObject("Scripting.FileSystemObject")

                             

                            if WScript.Arguments.Count = 0 then

                                WScript.Echo "Missing parameters"

                            end if

                             

                            FSO.MoveFile WScript.Arguments(0) &"\REPORT_NAME.pdf", WScript.Arguments(0) &"\NEW_REPORT_NAME_" & Year(Now) & Month(Now) & Day(Now) & Hour(Now) & Minute(Now) & Second(Now) & ".pdf"

                             

                             

                            4. The important parts here are the WScrip.Arguments and the MoveFile command. The Argument is what Masshunter will pass to the script to tell it where the report pdf file is, the MoveFile command is what we use to rename the file. The idea is we "Move" the file in the same place to give it a new name.

                             

                            5. There the script says"REPORT_NAME.pdf" in my example, replace with your Destination file name. From here you can either change the report name completely like I have above or use the same base file name and add to it. The script will do year month day hour minute second as you initially asked. But you can add other features if you like. I don't know that you can make it add the batch name or anything like that.

                             

                            6. Once you have this file you need to add a trigger for it in your report method.

                             

                            7. Go to Masshunter and open the report method editor:

                             

                            Click on "Edit Post Processes..."

                            Click "New"

                            Give your new Post Process Task a name, like "Rename_Report"

                            In the Executable file box add the file path type in the file path and script file name in full.

                            In the Arguments box use the $(ReportFolder) argument macro.

                             

                            8. Click "OK", Close the Post Processes dialog.

                            9. Now select the Post Process in the dropdown box of the report method editor:

                             

                            10. Save and Exit the report method editor.

                             

                            Run your report and cross your fingers...

                             

                            Now you  can obviously use the Move command to actually move your report somewhere else, say a central location that you want all your reports to go to. Or change the command to CopyFile to create a copy somewhere else withe the new name.

                             

                            Hopefully someone will find this useful, and I will accumulate enough good karma points for someone to answer my question .

                              • Re: How to define destination file name when generated report?
                                david_zhou

                                Hi darcyc :

                                thanks for your feedback~

                                for report mode = batch, this VBS is OK, because PDF file name is fixed.

                                thanks again for your idea.

                                for further requirements:

                                  1.if report mode = single sample, below error was reported.

                                  2.after PDF was generated, we hope put PDF backup to another path,

                                currently, i use .BAT implement this requirement.  can VBS do it?

                                BAT coded below:

                                @setlocal enableextensions enabledelayedexpansion
                                @echo on

                                set "datafolder=\\CNCANCHEMAP01\AnaysisReportBackup"
                                set filename=%~n1
                                set dir=%~dp1
                                set yy=%DATE:~0,4%
                                set mm=%DATE:~5,2%
                                set dd=%DATE:~8,2%
                                set "desfolder=%datafolder%\%yy%\%mm%\%dd%"

                                cd c:\
                                if not exist %datafolder% md %datafolder%

                                cd %datafolder%
                                if not exist %desfolder% md %desfolder%

                                echo Current directory is: !dir!

                                cd /d %dir%

                                echo %date% %time% >PostReportProcess.log
                                echo copy %filename%.pdf %desfolder% /y /v >>PostReportProcess.log

                                copy "*.pdf" %desfolder% /y /v >>PostReportProcess.log 2<&1

                                endlocal

                                  • Re: How to define destination file name when generated report?
                                    darcyc

                                    ok, For the single sample report.

                                    There's probably a more elegant way to do this but here's my solution.

                                    Assuming the destination file name started out as "Gen_Complete" and gets the sample info appended..
                                    Replace the FSO.MoveFile line with:

                                     

                                     

                                    StartFolder = WScript.Arguments(0) &"\"

                                     

                                     

                                    Set Folder = FSO.GetFolder(StartFolder)

                                     

                                     

                                    Set colFiles = Folder.Files

                                    For Each File in colFiles

                                       if instr(File.Name,"Gen_Complete") <> 0 AND instr(File.Name,".pdf") <> 0 then

                                           FSO.MoveFile WScript.Arguments(0) &"\" & File.Name, WScript.Arguments(0) &"\" & Left(File.Name,Len(File.Name)-4) & Year(Now) & Month(Now) & Day(Now) & Hour(Now) & Minute(Now) & Second(Now) & ".pdf"

                                       end if

                                    Next

                                     

                                     

                                    so this will find all files that contain the string "Gen_Complete" in the name, and change the name to append  year month day etc.

                                     

                                    copying the file to a new folder, yes vbs can do that, I haven't tested this bit but I guess you would do something like

                                     

                                     

                                    datafolder="\\CNCANCHEMAP01\AnaysisReportBackup"

                                     

                                    If FSO.FolderExists(datafolder) = False Then

                                     

                                    FSO.CreateFolder datafolder

                                    End If

                                     

                                     

                                    I'll be heading off soon but I hope that helps.

                                    1 person found this helpful
                                      • Re: How to define destination file name when generated report?
                                        david_zhou

                                        hi darcyc:

                                        Sorry for feedback to you so later.

                                        your supplementary solution is OK for single sample report rename.

                                        Can you help me add code "copying the file to a new folder" in rename VBS, same as function in my .BAT.

                                        thanks again´╝ü

                                          • Re: How to define destination file name when generated report?
                                            darcyc

                                            hi, I'll try.

                                             

                                            here's my attempt.

                                             

                                            go to the script you have, replace this part:

                                            StartFolder = WScript.Arguments(0) &"\"

                                             

                                            Set Folder = FSO.GetFolder(StartFolder)

                                             

                                            Set colFiles = Folder.Files

                                            For Each File in colFiles

                                               if instr(File.Name,"Gen_Complete") <> 0 AND instr(File.Name,".pdf") <> 0 then

                                                   FSO.MoveFile WScript.Arguments(0) &"\" & File.Name, WScript.Arguments(0) &"\" & Left(File.Name,Len(File.Name)-4) & Year(Now) & Month(Now) & Day(Now) & Hour(Now) & Minute(Now) & Second(Now) & ".pdf"

                                               end if

                                            Next

                                             

                                             

                                             

                                            With This:

                                             

                                            StartFolder = WScript.Arguments(0) &"\"

                                             

                                            Set Folder = FSO.GetFolder(StartFolder)

                                             

                                            archiveDirYear = "\\CNCANCHEMAP01\AnaysisReportBackup\" & Year(Now)

                                            archiveDirMonth = archiveDirYear & "\" & Month(Now)

                                            archiveDirDay = archiveDirMonth & "\" & Day(Now)

                                            archiveDir = archiveDirDay & "\"

                                             

                                            If FSO.FolderExists(archiveDirYear) = False Then

                                            FSO.CreateFolder archiveDirYear

                                            End If

                                            If FSO.FolderExists(archiveDirMonth) = False Then

                                            FSO.CreateFolder archiveDirMonth

                                            End If

                                            If FSO.FolderExists(archiveDirDay) = False Then

                                            FSO.CreateFolder archiveDirDay

                                            End If

                                             

                                            suffix = Year(Now) & Month(Now) & Day(Now) & Hour(Now) & Minute(Now) & Second(Now)

                                             

                                            Set colFiles = Folder.Files

                                            For Each File in colFiles

                                               if instr(File.Name,"Gen_Complete") <> 0 AND instr(File.Name,".pdf") <> 0 then

                                                   newname = Left(File.Name,Len(File.Name)-4) & suffix & ".pdf"

                                                   FSO.MoveFile StartFolder & File.Name, StartFolder & newname

                                                   FSO.CopyFile StartFolder & newname, archiveDir & newname

                                               end if

                                            Next

                                             

                                             

                                             

                                            I've tried to clean up the renaming part so it's a little easier to follow what's going on.

                                            Hope this works for you.

                                            1 person found this helpful