Opening Form "Phys. Inventory Journal" with a given Journal Template & Batch Name

How can i open the Form 392:“Phys. Inventory Journal” with a defined Journal Template Name and Journal Batch Name using C/AL Code? I tried several solutions using the Codeunit “Item Jnl. Managment” but I always failed :frowning:

Here is a section of a report 699 - calculate plan - req. worksheet I modified, so I can run the report in the job schedular every night. I also set a filter for locations, but that is separate from you concern. I don’t have access to cal/code in forms so I can not test for you solution, but you should be able to set the setting basically the same. for my use, I made seven separate reports, one for each location, which run every evening to bring up requsitions.

Documentation()
modifed standard report 699 to use set template and worksheet, so report can run unattended

Report - OnInitReport()
OrderDate := TODAY +20;
ToDate := TODAY +20;
CurrTemplateName := ‘REQ’;
CurrWorksheetName := ‘SF’;

Do you want to always open that form with a certain Journal Template/Batch or just under certain conditions (i.e. started from a certain place) ?

The Template would be always the same, the Batch depends on the lookuped Location Code in my Form.

One idea would be:

You create a new function (i.e. SetBatchName) in form 392 “Phys. Invt. Jnl” which receives the batch name as a parameter.

This one you need to save in a global variable (i.e. ForceBatchName, Code 10)

In the OnOpenFormTrigger you just put the following code inside the code which is already there:

ItemJnlMgt.TemplateSelection(FORM::“Phys. Inventory Journal”,2,FALSE,Rec,JnlSelected);
IF NOT JnlSelected THEN
ERROR(’’);
IF ForceBatchName <> ‘’ THEN
CurrentJnlBatchName := ForceBatchName;
ItemJnlMgt.OpenJnl(CurrentJnlBatchName,Rec);

Then you just need to call that function before you run the form like:

OnPush()
CLEAR(PhysInvtJnl);
PhysInvtJnl.SetBatchName(‘BLUE’);
PhysInvtJnl.RUN;

Thank you, I couldn’t use the solution 1 on 1 because my (NAV 3.7) Functions need other Parameters and the Template Selection wats to start a Form which I don’t want to start :slight_smile:

At least I put a new function in Form “Phys. Inventory Journal” and used some additional lines in the OpenForm Trigger like you explained.

SetCurrJnlTmplAndBatch(vco_TemplateName : Code[20];vco_BatchName : Code[20]) SETRANGE(“Journal Template Name”, vco_TemplateName);
gco_PredefinedBatchName := vco_BatchName;

I use it before opening the Form to Filter on my Template and to fill a Dummy Variable.

The OpenForm Trigger got these new lines:

IF gco_PredefinedBatchName <> ‘’ THEN
CurrentJnlBatchName := gco_PredefinedBatchName;

You cannot assign the Journal Batch Name to Variable “CurrentJnlBatchName” directly in the new function. It would be blank in the OpenForm Trigger :frowning: