Options

Transfering data to a journal

dabba23dabba23 Member Posts: 77
I have made a report for processing data from Employee Absence table to a Employee Absence Journal Line.

I simply cannot get the data over, as it complains about the Batch name being empty.

Can anyone see from the code, where I have gone wrong:


Employee Absence - OnPreDataItem()

EmpBatch.GET(EmpJournal."Journal Batch Name");
NextLineNo := 0;

Employee Absence - OnAfterGetRecord()

WITH EmpJournal DO BEGIN
IF NextLineNo = 0 THEN BEGIN
LOCKTABLE;
SETRANGE("Journal Batch Name","Journal Batch Name");
IF FIND('+') THEN
NextLineNo := "Line No.";
END;
NextLineNo := NextLineNo + 1;
INIT;
"Line No." := NextLineNo;

//other code in here, that shouldn't affect the error message!!!

INSERT(TRUE);
END;

Many thanks
Ann

Comments

  • Options
    Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    Could you please tell me what version of navision you are using since I've never seen employee absece with journal batches :?

    Well, actualy I have, but I've made these myself :D
  • Options
    dabba23dabba23 Member Posts: 77
    I'm using Navision 3.70, but I have made the journal myself too!!! That's why!
  • Options
    Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    Ah, that explains! :D

    If you use the debugger, where exactly does the error occur?

    Does this piece of code go OK?

    EmpBatch.GET(EmpJournal."Journal Batch Name");

    I am asking this because on first sight I cannot see the problem :(
  • Options
    dabba23dabba23 Member Posts: 77
    Well no, you are rigth that it breaks on EmpBatch.Get(EmpJournal."Journal Batch Name"), which does make sense to me!

    However, do I comment it out, it breaks on Emp Absence Jnl Line table on the trigger OnInsert, where I have AbsenceJnlBatch.Get("Journal Batch Name").

    Thats why I am lost!
  • Options
    Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    Yes, I guess a journal line wants/can want some journal batch.

    How do you start this report? Have you thought about putting the journal batch code in a variable and put it on the request form?

    You have to determine where you want to get the batch from.

    Is the EmpJournal record populated in the OnPreDataIem or is it empty?

    EmpBatch.GET(EmpJournal."Journal Batch Name");

    I hope this give you some clues as to where to start searching. :wink:
  • Options
    DenSterDenSter Member Posts: 8,304
    It errors out on GET because there is no such record in the table that you're getting from. To do this without erroring out, you need to make sure that those records are there.

    Needing a batch and template for journals is standard Navision functionality. What I usually do is give the user a place to enter a default for both in a setup table and populate the fields with those values.

    You can also turn on the debugger and open a standard Journal, and follow standard Navision code to populate the batch and template. That should give you some ideas as to how to develop that.
  • Options
    Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    DenSter wrote:
    Needing a batch and template for journals is standard Navision functionality. What I usually do is give the user a place to enter a default for both in a setup table and populate the fields with those values.

    This is only for journals that are not directly posted, otherwise you can post a journal line without Template/Batch/Line No.

    Look at codeunit 80 for example, no templates/batches etc there :D
  • Options
    DenSterDenSter Member Posts: 8,304
    I don't think codeunit 80 does an INSERT(TRUE) on the journal line table either (although I'd have to check that).
  • Options
    Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    Yes, this is true, all postings done by navision do no insert the journals, they directly post the line.
  • Options
    DenSterDenSter Member Posts: 8,304
    So... deducing from the fact that he is using the INSERT method, he's not sending the record into a posting routine, but wants to save the record. The only sensible reason to save a recod is to later access it again. Without a template and a batch, you won't be able to access a standard journal. SO, he needs both of those values.

    Elementary my dear Watson :) of course unless I'm not paying attention :-k
  • Options
    Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    Yes, this is true. In this case you need a Batch/Template/Line No.

    I just wanted to explain that it can be done without. :D

    I see you've read you Sherlock Holmes 8)

    This is getting another highjacked topic...
  • Options
    awarnawarn Member Posts: 261
    Basically there is in INIT called, but no code (shown) that fills in a Batch name.

    There needs to be code in between the INIT and the INSERT:


    INIT;

    "batch name" := '..............


    INSERT(true);
Sign In or Register to comment.