Run report and continue processing in parallel (non-modal)

I have searched the knowledgebase here without success . . .

I’m running Dynamics 5.01, SQL version.

I want to run a report from a form, and have the processing on the form continue as the report is running. I have tried:

REPORT.RUN(reportvariable, FALSE, FALSE); // (expecting this to work, and the form to carry on)

and

REPORT.RUNMODAL(reportvariable, FALSE, FALSE); // (expecting the form to wait until the report finished)

but there seems to be no difference. It I put an ERROR statement after the REPORT statement, in both cases the ERROR does not occur until after the report has finished.

Why does REPORT.RUN not work?

Thanks, Andy

NAV is a single threaded application, you will have to wait for the report to finish. You could start a new NAV session but if everyone does that you’ll run out of licenses pretty quickly.

Having experimented a bit further, it appears that

REPORT.RUN(reportvariable, TRUE, FALSE); // does show the request form, and processing carries on immediately in the form

REPORT.RUN(reportvariable, FALSE, FALSE); // not showing the request form causes the form to wait until the report is finished before continuing

So REPORT.RUN and REPORT.RUNMODAL seem to be identical if you do not show the request form. Can anyone confirm this?

Andy

The difference between RUN and RUNMODAL is while a form (a report’s request form, but it also works with regular forms) is displayed. With RUN, you are allowed to click on other forms. With RUNMODAL it does not allow you to click anything but that form.

Once the report is running you cannot do anything else, regardless of whether it was started using RUN or RUNMODAL. I guess you could say that the MODAL part refers to the requestform.

Thanks Deniel. That explains it, although I am disappointed . . . . .

I am trying to write a report scheduler (a form) that will start a report, and then monitor it, so that I can know it has failed if it has not finished in a certain amount of time. If it has not finished, then there doesn’t seem to be any code that I can execute to check.

Say I have 2 forms running in parallel, one to monitor, and the second to run the reports. While the second is running a report, will the first still run code in an OnTimer trigger?

Andy

I’ve never tried that scenario, you’d have to test it yourself. I would expect that if you have 2 forms running, both with say a 5 second interval, and one of them runs a process that takes more than 5 seconds, that the other form will have to wait for the first one to complete. Try it, put some tests together and see what happens.

You are right. This is what happens. We have Form A (runs the reports) and Form B (Monitors for reports finishing). Both run on a TimerInterval of 1 minute.

Form A. OnOpenForm - RUN FORM(B) which sets the Monitoring form going. Both forms run together. I know this because they display the time, and it increases every minute.

If Form A, OnTimer trigger, runs a report, then BOTH FORM A and B stop working, until the report is finished. So this does not get around the problem.

I’ll have to rethink the design of the project.

Andy

Why not use the Job Queue? You can have multiple instances run at the same time, and it is designed with the ability to monitor progress.

We looked at the job queue. We want to do things like 1) have dependent jobs (have one job that runs after another one, provided the first completes OK), and 2) email certain users if a job fails.

Also, our Dynamics support company told us that the job queue does not know if a job has failed or not . . . So we weren’t too impressed.

My solution is to run the scheduling of reports in one Dynamics session, and run the monitoring form in another Navision session, on the same server. That will work.

Thanks for your help and suggestions. At least I’m not going mad!

Andy

You can modify the Job Queue so that it has “parent” jobs, in other words certain jobs have to complete before the next job goes. It doesn’t take but a few hours.

You can insert one-time jobs in the Job Queue in C/AL code, so requirement 1 can be met with minimal development. The Job Queue also has something called “Job Queue Log Entries”, which includes a status that can be ‘Error’, and it even has a field for the error message itself.

Perhaps your NAV partner is not aware of the Job Queue’s capabilities.

Thanks for your suggestions about the job queue. Another thing we would need to overcome with the job queue, is running on multiple companies. We will want to schedule jobs for 6 or 8 companies in the same database, and have been told that we would have to buy 1 job queue per company. Is that true? Can the Job Queue be made to switch between companies (or can ANY CAL code do that)?

Andy

Yes, you can switch companies with C/AL code, although it can be complicated with, for lack of a better term, “long” processes. Rather, code that references a lot of tables. You have to switch companies for every table you call in the code.

The CHANGECOMPANY command is not feasibile when you are writing a job scheduler which must run reports (say month end reports, or MRP) on multiple companies. What I would want to do is:

Switch my session into a certain company using CAL code. Run the report in that company using CAL code. Switch to the next company, etc. Automatically.

I would most definitely never use CHANGECOMPANY for this. You’ll have to program every record variable to change company, and that’s just not realistic. The cost to develop such a thing would be much more than a few NAS licenses.

NAS is essentially a NAV client session without a UI that runs as a Windows service. This is why you have to set it up with a database name and company name. There are some tricks around having multiple instances of NAS, each for a different company, and then you have a process that starts and stops them so that at any time you only have one of them running. There’s also a trick where you set up web services for each company, and you have a Job Queue run that includes a company parameter, and sends the requests in as web service calls. There are probably other ways to work it.

If you’re going to use plain Job Queue though, you need a NAS license for each company. Ask your NAV partner what the NAS licenses would cost, and discuss with them what it would cost to develop the alternative.

Daniel, Thanks for this. By this time, I am virtually there with the coding to schedule jobs, and monitor them for failure etc. The only question is how to run them in a multiple company database. The solution we have hit on, is to have a dedicated PC, run multiple instances of Navision on it, with different .zup files, which identify the different companies that we want to run the scheduling in. I suppose this is like running 5 (say) instances of our own ‘NAS’ running a job queue per company. I have made the main Job table I have created into a ‘DataPerCompany = No’ table. This way, I only need 1 instance of the monitoring Navision session, which will monitor all jobs, for all companies. It does not matter which company the monitoring session logs into. This will be our solution, which will be easier to maintain than having to learn new techniques involved with the NAS and Navision Job Queue module. Thanks for all your thought, Andy

Right I see what you’re saying. It’s essentially the same idea, only you chose to run regular NAV sessions instead of NAS instances. Mind you though that anyone that can physically walk up to this PC can use those sessions to the limitations of the user that you use to run those processes, so you’ll have to think about security.

I’m still not sold on whether you couldn’t have used standard Job Queue though, but the idea with the monitoring session is pretty clever. Glad to hear you found a resolution, thanks for following up [:D] [Y]