A report needs to be run using NAS, therefore, we cannot have any popup windows (i.e. message, request windows, error, etc).
If I were to run the report (50006) manually, in the request window, I need to input a PostingDate. Since we are running the report using NAS, I need to suppress this request form and apply the posting date manually. Therefore in order to do this, in the report I created a new function called: SetDefaults which contains a parameter called 'DefaultDate' of date type. In the function I have the following code:
PostingDate := Default Date;
I am running this report using a codeunit. In the Codeunit, I defined a variable called Report1 (with report type variable). Then I wrote the following line of code:
Report1.SetDefault(TODAY);
REPORT.RUN(50006, FALSE);
The request form is suppressed, however, the PostingDate does not contain TODAY.
Another thing to notice is that, in Report1 (50006) there is a check in OnPreReport trigger:
If PostingDate = 0D then
IF GUIALLOWED THEN
error('please enter the date')
I am not really sure how to pass the date from the codeunit and make the report remember the value. I thought this is how I would do it. What am I missing? The Event Viewer always contains, please enter the date.
0
Answers
From this:
Report1.SetDefault(TODAY);
REPORT.RUN(50006, FALSE);
To this:
Report1.SetDefault(TODAY);
Report1.USEREQUESTFORM(FALSE);
Report1.RUN;
Thank you so much. That worked. =D> \:D/