Passing Parameters to Reports - Watch Out for this !!

We use the well document technique of passing parameters to reports and then running them from Codeunits.

Recently we used this technique to automate the Inventory Periodic reports

  1. Adjust Cost Item Entries.

  2. Post inventory Costs to G/L

Everything worked perfectly at first then one day we found a problem. The Post Inventory Costs to G/L report had run using parameters different from those supplied by the calling Codeunit.

We investigated and found that the parameters used were the same as those used when Post Inventory Costs to G/L was run from the Periodic Activites Menu.[:^)]

We experimented and we have found that if the Request Form property SaveValues is set to Yes then the report will use parameter values stored in the zup file and these values will overwrite parameters supplied using the parameter passing technique.

Our solution is to set the SaveValues property to No and now all is well again.

I hope that this note will prevent anyone else having a problem.[;)]

The problem is the point in time when the RequestForm loads the values from the Zup-File. One might expect that the values are loaded before the OnInit but they don’t. So you push your parameters to the report (try a message-output of your values in the OnInit-trigger) and then Navision comes and overwrites them again.

What I wanted to say is: In some situations you don’t want to disable the SaveValues-Functionality.

The Workaround is working with new global variables which you can set (over functions) from the calling codeunit and then overwrite the standard global variables after the OnOpenForm-trigger.

So you have both: SaveValues and own parameters…

Wouldn’t it be a kind of weird to do this in the OnOpenForm trigger ? Such codeunits are mostly used for unattended (UseRequestform = False) use.

So better to use the “OnPreReport” trigger.

Ok this is a additional szenario - you are right for this.

But can use OnOpenForm if you want to see the Form with initialized RequestForm :wink:

Exactly what I was going to say.

Pass to the function a Boolean as the first parameter (setAutoValues), something like “newAutoRun” then on the OnPreReport

If AutoRun then begin

//Clear Old values

//Don’t just set the values you want as the values you don’t change might have a value in them from the ReqForm

//Set new Values

End;

Since the Request Form was still run with its saved values it should maintain them next time a user runs the form.

T