Problem inserting: Last row replace.

Guga84Guga84 Member Posts: 24
edited 2007-11-27 in Navision Attain
Hi, I’m trying to insert new lines in the "Journal Line Dimension" table, but at least it just inserts the last one, the others are replaced by the last.

I think the primary key is ok in each record, so I don’t know what could be wrong.
Does anybody know why this happens?


Here is a piece of code where I do the insert.
CLEAR(rJournalLineDimension);

rJournalLineDimension.VALIDATE(rJournalLineDimension."Table ID",81);

rJournalLineDimension.VALIDATE(rJournalLineDimension."Journal         Template Name" , rGenJournalLine."Journal Template Name");

rJournalLineDimension.VALIDATE(rJournalLineDimension."Journal Batch Name", rGenJournalLine."Journal Batch Name");

rJournalLineDimension.VALIDATE(rJournalLineDimension."Journal Line No.", rGenJournalLine."Line No.");

rJournalLineDimension.VALIDATE(rJournalLineDimension."Allocation Line No.", 0);

rJournalLineDimension.VALIDATE(rJournalLineDimension."Dimension Code", rGeneralLedgerSetup."Shortcut Dimension 3 Code" );
          
rJournalLineDimension.VALIDATE(rJournalLineDimension."Dimension Value Code",vAuxSD3C);

WITH rJournalLineDimension DO BEGIN
                 MESSAGE ('%1,%2,%3,%4,%5,%6,%7',FORMAT ("Table ID"),"Journal Template Name","Journal Batch Name",
                                    "Journal Line No.","Allocation Line No.","Dimension Code","Dimension Value Code");
END;

IF (rJournalLineDimension.INSERT) THEN
                 MESSAGE('Inserta OK');


The messages are correct in each loop.

Thanks.

Answers

  • krikikriki Member, Moderator Posts: 9,115
    Well this looks good, except 1 detail:
    rJournalLineDimension.VALIDATE(rJournalLineDimension."Table ID",81);
    
    should be:
    rJournalLineDimension.VALIDATE(rJournalLineDimension."Table ID",DATABASE::"G/L Journal Line");
    
    Never use a number to assign some object-ID to some variable, but always use the option for it.

    What is the code for looping?
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • mart1n0mart1n0 Member Posts: 123
    You have a 0 hardcoded as Allocation Line No., shouldn't this increment?
  • Guga84Guga84 Member Posts: 24
    mart1n0 wrote:
    You have a 0 hardcoded as Allocation Line No., shouldn't this increment?

    The primary key should be unique even is this number is always 0, because the "line. No." changes. :shock:
    If I follow the standard the "Allocation Number" might be 0, so I can't take this as a chance.
    However, if I increment this number, it inserts some dimensions correctly, but not the 1 and 2 dimension. So I think the problem could be here.

    The code is for insert new lines in Gen Journal Line, from an Excel sheet.
    As the Gen Journal Line only have shortcut for dimensions 1 and 2, I have to insert the others dimensions by code. But the dimension 1 and 2 are not correctly inserted, so

    ¿Does anybody know if in Navision Attain the dimension 1 and 2 are automatically inserted in the "Journal line dimension " table when you validate a journal line?

    Thanks
  • krikikriki Member, Moderator Posts: 9,115
    Guga84 wrote:
    ¿Does anybody know if in Navision Attain the dimension 1 and 2 are automatically inserted in the "Journal line dimension " table when you validate a journal line?
    Yes, BUT:
    You need to leave the "Line No." = 0 and use VALIDATE("Shortcut Dimension 1/2 Code",'Some value');. This saves the data in globals in the record-variable of table 81 until you do a INSERT(TRUE);
    And remember : just BEFORE doing the INSERT(TRUE), you need to change the "Line No.".

    PS : If you assign a number to "Line No." before doing the validates, this will save the dimensions directly to the table, BEFORE you do the INSERT(TRUE). Best is to do all at the same moment.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • Guga84Guga84 Member Posts: 24
    At the end, I insert the lines with Allocation Line No different to 0 and after the insert I modify the "Allocation Line No" to 0. It's not the best solution but it works. :wink:
Sign In or Register to comment.