Report Writer, Macros & and my attempt at saving some time

One of the common requests that I get when it comes to editing things like invoice layouts is being able to add extra comment lines. Both line comments and header comments.

David Musgrave, creator of GP Power Tools made a great post back in February 2011 about doing this using the report writer functions RW_SOPLineCommentText and RW_SOPHDRCommentText.

Since I do this fairly regularly, I decided to see if there is a way for me to streamline this a little more, as it requires you to make 8 new fields to replace the four original comment fields, once you do it a few times, you do get a bit quicker at creating them, but I’m always looking for ways to save time and make my job a little easier.

Even if you use David’s unsupported method of exporting a package file and then using copy/paste to create the extra fields and rename them, it still takes a little while to get it all done. I decided to see if I could use a Macro to create the fields.

For those of you who don’t know what a macro is, it’s a set of instructions that you record into a .mac file which you can run in Dynamics GP (other software also have variations of this, such as Microsoft Office products, etc.). These sets of instructions are pretty specific, for example, if you have a specific window open when you record the macro, it expects to have this window open when you run the macro again or the instructions will fail to run properly.

I recorded a macro of myself creating one of the fields and then edited it using Notepad++ to copy/paste the sections that created each fields and edited where required to change things like the field name and the line number. Using this method, I managed to get this part of the process, which would usually take at least 10-15 minutes, or more, depending on your ability with Report Writer, down to 32 seconds using the macro.

All in all, it took the same kind of time to make the macro as it did if I were to make the changes manually, except I can now save this time each time I need to add these comments. The macro adds the line comments but can easily be adapted to add the header comments too. The only thing left to do is to follow final part of David’s post and edit the suppression fields.

I did try and see if I could include this process in my macro, but you are unable to add the fields to the suppression calculated fields without the line comments being dragged onto the report and the macro didn’t really like this process as the screen has to be in a certain position for it to work properly.

Something to revisit one day when I have nothing else to do!

If you would like a copy of the macro, you can download it below.

GetInterfaced_CommentLines [7zip] [2kb]

For the macro to run properly, you need to have report designer open, ‘calculated fields’ selected in the Toolbox and the report you are editing in focus. Then, go to the Macro menu and click Play.

You can then select the .mac file you wish to run.

Feel free to take the macro and edit it to meet your needs!


Share on Social Media: