Auto Journal Posting Issue

write2souravwrite2sourav Member Posts: 113
Hi,
I am automatically creating a multiline journal through Gen Jnl Line. I am populating shortcut dimensions through code using the ValidateShortcutDimCode() function. When i am trying to post the journal programattically, system is asking for dimension on a particular line. I have already provided the same dimension at the time of creating journal...

I am using the following line for posting
CUGenJnlPostLine.RUN(Rec81);

Where Rec81 is a var of table 81.

If i post the journal manually, by blocking the above code (only inserting in table 81 through program), the same is posted without any error. What could be the reason..
Plz help......

Comments

  • kinekine Member Posts: 12,562
    If you are not inserting the Jnl line but just filling the values, the dimension entries will not be filled in (the line no. is 0). You need to use RunWithCheck function of the codeunit to pass JnlLine and temp table with dimensions.
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • matttraxmatttrax Member Posts: 2,309
    Or just VALIDATE the fields on the General Journal Line. That will take the appropriate actions for the dimensions and insert the records in to the Journal Line Dimension table.
  • kinekine Member Posts: 12,562
    matttrax wrote:
    Or just VALIDATE the fields on the General Journal Line. That will take the appropriate actions for the dimensions and insert the records in to the Journal Line Dimension table.
    But only if you are really inserting the record by Insert(True)... :-)
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • write2souravwrite2sourav Member Posts: 113
    Hi,
    I am unable to post the journal automatically. The same error is coming. The code is as follows:


    IF CONFIRM('Do you want to create the journal lines',TRUE) THEN BEGIN
    TESTFIELD("RTGS Date");
    TESTFIELD("Amount to be Remitted");
    TESTFIELD(Type);
    TESTFIELD("Beneficiary Code");
    TESTFIELD("Applicant A/C No.");
    TESTFIELD("Voucher Posting Date");

    IF ("Beneficiary Type"="Beneficiary Type"::Customer) OR ("Beneficiary Type"="Beneficiary Type"::Vendor) THEN BEGIN
    RecGenJnlLine.RESET;
    RecGenJnlLine.SETRANGE("Journal Template Name",RecGLSetup."RTGS Template Name");
    RecGenJnlLine.SETRANGE("Journal Batch Name",RecGLSetup."RTGS Batch Name");
    IF RecGenJnlLine.FIND('+') THEN
    LineNo:=RecGenJnlLine."Line No."+10000
    ELSE
    LineNo:=10000;
    END;

    IF ("Beneficiary Type"="Beneficiary Type"::Bank) THEN BEGIN
    RecGenJnlLine.RESET;
    RecGenJnlLine.SETRANGE("Journal Template Name",RecGLSetup."RTGS Template Name CV");
    RecGenJnlLine.SETRANGE("Journal Batch Name",RecGLSetup."RTGS Template Batch CV");
    IF RecGenJnlLine.FIND('+') THEN
    LineNo:=RecGenJnlLine."Line No."+10000
    ELSE
    LineNo:=10000;
    END;

    DivCode:='DIV BLK'; //Hard Coded

    CLEAR(RecGenJnlLine);
    RecGenJnlLine.RESET;
    RecGenJnlLine.INIT;
    IF ("Beneficiary Type"="Beneficiary Type"::Customer) OR ("Beneficiary Type"="Beneficiary Type"::Vendor) THEN
    RecGenJnlLine.VALIDATE("Journal Template Name",RecGLSetup."RTGS Template Name")
    ELSE
    RecGenJnlLine.VALIDATE("Journal Template Name",RecGLSetup."RTGS Template Name CV");
    IF ("Beneficiary Type"="Beneficiary Type"::Customer) OR ("Beneficiary Type"="Beneficiary Type"::Vendor) THEN
    RecGenJnlLine.VALIDATE("Journal Batch Name",RecGLSetup."RTGS Batch Name")
    ELSE
    RecGenJnlLine.VALIDATE("Journal Batch Name",RecGLSetup."RTGS Template Batch CV");
    RecGenJnlLine."Line No.":=LineNo;
    RecGenJnlLine.VALIDATE("Posting Date","Voucher Posting Date");
    IF ("Beneficiary Type"="Beneficiary Type"::Vendor) THEN
    RecGenJnlLine.VALIDATE("Document Type",RecGenJnlLine."Document Type"::Payment)
    ELSE
    RecGenJnlLine.VALIDATE("Document Type",RecGenJnlLine."Document Type"::" ");
    IF "Beneficiary Type"="Beneficiary Type"::Bank THEN
    BEGIN
    IF RecGenJnlBatch.GET(RecGLSetup."RTGS Template Name CV",RecGLSetup."RTGS Template Batch CV") THEN
    RecGenJnlLine.VALIDATE("Document No.",NoSeriesMgt.GetNextNo(RecGenJnlBatch."No. Series",WORKDATE,FALSE));
    END
    ELSE
    BEGIN
    IF RecGenJnlBatch.GET(RecGLSetup."RTGS Template Name",RecGLSetup."RTGS Batch Name") THEN
    RecGenJnlLine.VALIDATE("Document No.",NoSeriesMgt.GetNextNo(RecGenJnlBatch."No. Series",WORKDATE,FALSE));
    END;
    IF ("Beneficiary Type"="Beneficiary Type"::Customer) THEN
    RecGenJnlLine.VALIDATE("Account Type",RecGenJnlLine."Account Type"::Customer);
    IF ("Beneficiary Type"="Beneficiary Type"::Vendor) THEN
    RecGenJnlLine.VALIDATE("Account Type",RecGenJnlLine."Account Type"::Vendor);
    IF ("Beneficiary Type"="Beneficiary Type"::Bank) THEN
    RecGenJnlLine.VALIDATE("Account Type",RecGenJnlLine."Account Type"::"Bank Account");
    RecGenJnlLine.VALIDATE("Account No.","Beneficiary Code");
    RecGenJnlLine.VALIDATE("External Document No.","RTGS No.");
    RecGenJnlLine.VALIDATE("Gen. Posting Type",RecGenJnlLine."Gen. Posting Type"::" ");
    RecGenJnlLine.VALIDATE(Amount,"Amount to be Remitted");
    RecGenJnlLine.VALIDATE("Shortcut Dimension 1 Code",'HO');
    IF ("Beneficiary Type"="Beneficiary Type"::Bank) THEN
    RecGenJnlLine.ValidateShortcutDimCode(3,DivCode);
    IF RecDefDim.GET(270,"Beneficiary Code",'BANK') THEN
    RecGenJnlLine.ValidateShortcutDimCode(7,RecDefDim."Dimension Value Code");
    IF RecGenJnlLine.INSERT(TRUE) THEN;
    NewDocNo:=RecGenJnlLine."Document No.";

    //Balancing Line
    IF ("Beneficiary Type"="Beneficiary Type"::Customer) OR ("Beneficiary Type"="Beneficiary Type"::Vendor) THEN
    RecGenJnlLine.VALIDATE("Journal Template Name",RecGLSetup."RTGS Template Name")
    ELSE
    RecGenJnlLine.VALIDATE("Journal Template Name",RecGLSetup."RTGS Template Name CV");
    IF ("Beneficiary Type"="Beneficiary Type"::Customer) OR ("Beneficiary Type"="Beneficiary Type"::Vendor) THEN
    RecGenJnlLine.VALIDATE("Journal Batch Name",RecGLSetup."RTGS Batch Name")
    ELSE
    RecGenJnlLine.VALIDATE("Journal Batch Name",RecGLSetup."RTGS Template Batch CV");
    RecGenJnlLine."Line No.":=LineNo+10000;
    RecGenJnlLine.VALIDATE("Posting Date","Voucher Posting Date");
    IF ("Beneficiary Type"="Beneficiary Type"::Customer) OR ("Beneficiary Type"="Beneficiary Type"::Bank) THEN
    RecGenJnlLine.VALIDATE("Document Type",RecGenJnlLine."Document Type"::" ")
    ELSE
    RecGenJnlLine.VALIDATE("Document Type",RecGenJnlLine."Document Type"::Payment);
    RecGenJnlLine.VALIDATE("Document No.",NewDocNo);
    RecGenJnlLine.VALIDATE("Account Type",RecGenJnlLine."Account Type"::"Bank Account");
    RecGenJnlLine.VALIDATE("Account No.","Applicant A/C No.");
    RecGenJnlLine.VALIDATE("External Document No.","RTGS No.");
    RecGenJnlLine.VALIDATE("Gen. Posting Type",RecGenJnlLine."Gen. Posting Type"::" ");
    RecGenJnlLine.VALIDATE(Amount,-("Amount to be Remitted"));
    RecGenJnlLine.VALIDATE("Shortcut Dimension 1 Code",'HO');
    RecGenJnlLine.ValidateShortcutDimCode(3,DivCode);
    IF RecGenJnlLine.INSERT(TRUE) THEN;

    CUGenJnlPostLine.RUN(RecGenJnlLine); //"Gen. Jnl.-Post Line"

    The shortcut dimension for Bank is populated when the "Applicant A/C No." field is filled.
    But again it is asking for the same when i post the journal automatically using
    CUGenJnlPostLine.RUN(RecGenJnlLine);.

    Plz advice
  • kinekine Member Posts: 12,562
    As each time, I recommend to use this pattern to insert the record:
    MyRec.INIT;
    //Assigning/Validating primary key fields
    MyRec.INSERT(True);
    //Assigning/Validating other fields
    MyRec.MODIFY(True);
    

    This pattern is closest to the manual entry of data and will lead to correctly created record.
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • rdebathrdebath Member Posts: 383
    1. You shouldn't be hiding any errors from the INSERT(TRUE) statements because if you get one there's a problem.
    2. Calling the RUN trigger of the G/L posting codeunit only allows you to set GD1 and GD2
    3. If creating any record in NAV that it's often best to follow the route that the Forms do when creating the record, especially if you don't understand all the code on the table. ie:
      1. Clear the record
      2. Populate the primary key
      3. Insert the record
      4. Populate other fields
      5. modify the record.
      and call all the triggers.
    4. You probably want to call the batch post routine CU13 to do your posting.
    5. Please wrap your code in code tags on mibuso
  • write2souravwrite2sourav Member Posts: 113
    Hi,
    Thanks to all. I have finally solved the issue with ur suggestions....
Sign In or Register to comment.