The Power of......Batch Scripts!

downtap
Member Posts: 18
Now, this may be common knowledge for all you veterans out there, but I didn't find too much information on the topic.
Some of us may have loads and loads of documents/images/files outside of Navision that may need to be compiled or retrieved for other functions. For example, my company has loads of images that get digitally delivered to our clients on a daily basis.
Before, we used to grab and compile these manually before sending them on to our clients. But, with all the data of what needs to be grabbed existing within Navision, I knew there had to be an easier way.
Please note, all code has been simplified to the minimal needed. Expand upon as necessary.
What I first did, was create a processing only report to create the batch file.
OnPreDataItem:
OnPostDataItem:
The images to grab are organized by a specific Document No., hence using that as the common variable to grab the data. I'm using text constants for the script for ease, but you may not find that necessary. The use of the SHELL command will run the batch file automatically after creating it. In an advanced application of this, I have several functions running on every record. Those all simply need to be called in OnAfterGetRecord. To state the obvious, for any script that needs to run only once at the beginning, call it on the OnPreDataItem. And for any script that needs to run only once at the end, call it on OnPostDataItem. For instance in my application of this creates a batch file as such:
DocNo=The document no. from Navision I'm compiling images from. This script for us, will take individual groups of images that are stored by date in separate places and copy them all to a new central location, so that they can all be zipped up into one package easily. (Note, I am using the 7-zip utility to zip the images) It may not be necessary to copy all the files, but for us it is necessary.
I know this may not be a common need, but being resourceful and coming up with a process utilizing Navision's data power and a little outside of the box thinking, has saved us a tremendous amount of time.
Another quick example we use by utilizing pdftoolkit:
I've obviously simplified this a bunch, but same premise as before. With pdftoolkit, am able to grab individual pdf images, or groups of pdf images and create a cingular pdf. This process for us is great to process multiple document numbers all at once.
Some of us may have loads and loads of documents/images/files outside of Navision that may need to be compiled or retrieved for other functions. For example, my company has loads of images that get digitally delivered to our clients on a daily basis.
Before, we used to grab and compile these manually before sending them on to our clients. But, with all the data of what needs to be grabbed existing within Navision, I knew there had to be an easier way.
Please note, all code has been simplified to the minimal needed. Expand upon as necessary.
What I first did, was create a processing only report to create the batch file.
OnPreDataItem:
DocNo := "Document No."; WITH OutFile DO BEGIN TEXTMODE := TRUE; WRITEMODE := TRUE; CREATE(STRSUBSTNO('FullFilePath\BatchScripts\%1.bat', DocNo)); CREATEOUTSTREAM(OutFileStream); END;OnAfterGetRecord:
BatchText := STRSUBSTNO(Text001); OutFileStream.WRITETEXT(STRSUBSTNO('%1%2',BatchText,CRLF));
OnPostDataItem:
OutFile.CLOSE; SHELL(STRSUBSTNO(''FullFilePath\BatchScripts\%1.bat', DocNo));
The images to grab are organized by a specific Document No., hence using that as the common variable to grab the data. I'm using text constants for the script for ease, but you may not find that necessary. The use of the SHELL command will run the batch file automatically after creating it. In an advanced application of this, I have several functions running on every record. Those all simply need to be called in OnAfterGetRecord. To state the obvious, for any script that needs to run only once at the beginning, call it on the OnPreDataItem. And for any script that needs to run only once at the end, call it on OnPostDataItem. For instance in my application of this creates a batch file as such:
pushd \\MyBatchFileLocation\ mkdir \Images\2009-12-23 mkdir \ImagePacks\2009-12-23\DocNo copy \OriginalImageLocation1\*.tif \NewImageLocation\ copy \OriginalImageLocation2\*.tif \NewImageLocation\ copy \OriginalImageLocation3\*.tif \NewImageLocation\ copy \OriginalImageLocation4\*.tif \NewImageLocation\ copy \OriginalImageLocation5\*.tif \NewImageLocation\ copy \OriginalImageLocation6\*.tif \NewImageLocation\ copy \OriginalImageLocation7\*.tif \NewImageLocation\ copy \OriginalImageLocation8\*.tif \NewImageLocation\ copy \OriginalImageLocation9\*.tif \NewImageLocation\ 7za a -tzip /NewImageLocation/DocNo.zip /NewImageLocation/*
DocNo=The document no. from Navision I'm compiling images from. This script for us, will take individual groups of images that are stored by date in separate places and copy them all to a new central location, so that they can all be zipped up into one package easily. (Note, I am using the 7-zip utility to zip the images) It may not be necessary to copy all the files, but for us it is necessary.
I know this may not be a common need, but being resourceful and coming up with a process utilizing Navision's data power and a little outside of the box thinking, has saved us a tremendous amount of time.
Another quick example we use by utilizing pdftoolkit:
pushd \\MyBatchFileLocation\ mkdir \ImagePacks\2010-01-14 pdftk /PDFLocation1/Doc1.pdf /2ndPDFLocation/*.pdf output /ImagePacks/DocNo.pdf pdftk /PDFLocation2/Doc1.pdf /2ndPDFLocation/*.pdf output /ImagePacks/DocNo.pdf pdftk /PDFLocation3/Doc1.pdf /2ndPDFLocation/*.pdf output /ImagePacks/DocNo.pdf pdftk /PDFLocation4/Doc1.pdf /2ndPDFLocation/*.pdf output /ImagePacks/DocNo.pdf pdftk /PDFLocation5/Doc1.pdf /2ndPDFLocation/*.pdf output /ImagePacks/DocNo.pdf pdftk /PDFLocation6/Doc1.pdf /2ndPDFLocation/*.pdf output /ImagePacks/DocNo.pdf pdftk /PDFLocation7/Doc1.pdf /2ndPDFLocation/*.pdf output /ImagePacks/DocNo.pdf
I've obviously simplified this a bunch, but same premise as before. With pdftoolkit, am able to grab individual pdf images, or groups of pdf images and create a cingular pdf. This process for us is great to process multiple document numbers all at once.
0
Comments
-
Just one hint: Do not use .bat extension but .cmd. Bat was used for old 16bit applications. .cmd is for 32/64 bit. But yes, it works with both, just wanted to extend your knowledge... ;-)0
-
Did not know that. Good to know!0
-
Good post! Thanks!
Tino Ruijs
Microsoft Dynamics NAV specialist0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions