My user was creating a SmartList Builder report yesterday and asked me a question that had me initially stumped.
The goal was to run the report and restrict the data to the previous month – not the current month.
Figure 1: Simple SLB SmartList
For this, we will just report on the Purchase Order Work table and to make it easier to work with we’ll just select a few identifying fields – the Document Date in particular.
So of course – we go to the Restrictions window to add our restriction.
Figure 2: Begin/End of Month option
And notice immediately that while we have a options for “Month”, we only have Beginning of Month and End of Month which implies the current month.
So out of the box restrictions aren’t going to be helpful to make this work for us.
Now of course we could create a custom SQL view by hand to return the data and restrict it for us – but that wouldn’t be very interesting for this article. And a downside to this approach is that you end up with a custom view that is external to the SmartList Builder that you have to maintain.
So if we don’t have a restriction for BOM or EOM, what is Plan B?
Well, if we can write SQL to figure out if a given date is within the previous month, can we restrict by that?
And that is our answer – a calculated field.
In it, we use SQL to set a value of the calculated return to have it check our DOCDATE and then check to see if it is within our expected period. And if so, return a 1 – otherwise return 0.
Figure 3: Calculation
The text of the calculation is:
DOCDATE >= DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE())-1, 0)
DOCDATE <= DATEADD(MONTH, DATEDIFF(MONTH, -1, GETDATE())-1, -1)
Now that we have the results of this so the calculation shows if it meets our criteria, we just need to create the Restriction.
Figure 4: Filter data with restriction
Now SLB will restrict the results of the calculation to 1 which would then be the records we expect to see.
Running the report in SLB – we see that indeed that the only data that displays is from the previous month.
Figure 5: Restricted data displayed
The Beginning of Month and End of Month restrictions that are out of box are using the GP User Date but it is worth noting that since we are pulling the data from SQL directly using GetDate(), the restriction is always going to be the date from SQL. Now ideally we’d be able to restrict by using the GP User Date instead because then I can change the report data by changing my User Date in Dynamics GP. However, since the User Date isn’t stored anywhere in SQL that I’m aware of and SLB doesn’t give us an option for “User Date” in the Special Fields, I don’t see a way to use that in any kind of calculation/restriction.
If I figure out a way to do this (without cheating and writing custom code in Extender Enterprise or VBA), I’ll update the article and sample to use that method.
Attached is the SmartList Builder report that I used from GP 2016.