How to open Item Journal with a selected Batch Name

TbiTbi Member Posts: 33

I think this is a easy question. but I'm stuck here.
In my codeunit I am inserting some lines in the Item Journal. And then I want to open the Item Journal form (40) to display the records. But the form always opens with the Batch Name the user visited last. So how can I open the Item Journal and show records in the Batch I want?


  • Options
    DenSterDenSter Member Posts: 8,304
    Form 40 has a global variable called "CurrentJnlBatchName". Set this to your batch before you run the form, and that should do the trick.

    Also, you could try using the 'ItemJnlManagement' codeunit (number 240) to open the form, by sending in your freshly created item journal line variable. I'm not sure, but I wouldn't be surprised if that will open it on the right batch.
  • Options
    TbiTbi Member Posts: 33

    Thanks for reply.

    I have tried ItemJnlManagement, but that did not solve the problem. And I have not seen any examples on how to set a global variable in a form before opening it from a codeunit.. I have tried to set it in a function in the form, but it doesn't seem to work. How is the easiest way to do this?
  • Options
    DenSterDenSter Member Posts: 8,304
    I don't know if it'll work, but that variable is what drives the Batch selection. The form is set to remember the user setting, so that's how it gets the last one.

    Let's see, I'm doing this without looking at Navision, so let me know if the details are not right..... you'll have to add a function to the form to set this variable. So open the form in design mode, open the globals on the Functions tab and add a line in there called SetBatchNumber or something. Click the Locals button and enter a Code10 parameter, let's call it parBatchCode.

    Next, in the trigger you program this:
    CurrentJnlBatchName := parBatchCode;
    Save and exit the form designer.

    Now in your calling object (you can test this by just creating a new blank form with a textbox linked to a Code10 variable representing the Batch Code called MyBatchCode and a button that will call the Journal form), you declare a form variable for the Item Journal Form, let's call it ItemJnlForm. In the button click trigger:
    And that should open the form with the right Batch number. Of course you wouldn't need the new form if you already have the form programmed in your other object.

    Note by the way that if you press F5, that you will see your SetBatchNumber function, and it even shows you which parameters you need.

  • Options
    TbiTbi Member Posts: 33
    Thanks for all help.
    I tried this, but it din't work. It is not possible to set CurrentJnlBatchName in a function before the Journal form opens, in some way this is set back to selected user setting. But I found a solution. I created a new global variable in the Journal form and sat this in a function first, and then I checked on this in the OnOpenForm() trigger on the Journal form. It worked..
  • Options
    DenSterDenSter Member Posts: 8,304
    Right, that'll work. Getting creative there, I like it :)

    I knew the CurrentJnlBatchName variable was a tricky one, and the next step would have been for me to actually open the form and figure that out, but since you have it working another way I won't do that.
Sign In or Register to comment.