XMLport 2013 import line already exist

ilovenavilovenav Member Posts: 9
edited 2014-03-10 in NAV Three Tier
please help, im newbie to this

when i import it to nav the error show that line no 10000 already exist.
i check the Item journal line, no data at all.
if i debug, it pointing to "IF IJL1.FINDLAST THEN BEGIN"

this is my code :
IJL_ - Import::OnBeforeInsertRecord()
IJL1.RESET;
IJL1.SETRANGE("Journal Template Name",'PHYS. INVE' );
IJL1.SETRANGE("Journal Batch Name",BatchName);
IJL1.SETRANGE("Source Code",'PHYSINVJNL');
IF IJL1.FINDLAST THEN BEGIN
LineNo := IJL1."Line No.";
END;
LineNo += 10000;

IJL_.RESET;
WITH IJL_ DO BEGIN
IJL_."Journal Template Name" := 'PHYS. INVE';
IJL_."Journal Batch Name" := BatchName;
IJL_."Line No." := LineNo;
VALIDATE(IJL_."Item No.",ItemNo);
IJL_."Source Code" := 'PHYSINVJNL';
CLEAR(VarDate);
EVALUATE(VarDate,PostDate);
VALIDATE(IJL_."Posting Date",VarDate);
VALIDATE(IJL_."Entry Type",IJL_."Entry Type"::"Positive Adjmt.");
VALIDATE(IJL_.Description,Desc);
VALIDATE(IJL_."Location Code",Loc);
CLEAR(VarDec);
EVALUATE(VarDec,Qty);
VALIDATE(IJL_.Quantity,VarDec);
VALIDATE(IJL_."Unit of Measure Code",UOM);
IJL_.INSERT;
END;

sorry for my poor english
thanks before

Comments

  • geordiegeordie Member Posts: 655
    Hi, I think you need to change this code
    IF IJL1.FINDLAST THEN BEGIN
    LineNo := IJL1."Line No.";
    END;
    LineNo += 10000;
    

    In
    IF IJL1.FINDLAST THEN
      LineNo := IJL1."Line No."
    ELSE
      LineNo += 10000;
    

    And then it should work.
  • ilovenavilovenav Member Posts: 9
    geordie wrote:
    Hi, I think you need to change this code
    IF IJL1.FINDLAST THEN BEGIN
    LineNo := IJL1."Line No.";
    END;
    LineNo += 10000;
    

    In
    IF IJL1.FINDLAST THEN
      LineNo := IJL1."Line No."
    ELSE
      LineNo += 10000;
    

    And then it should work.

    still got the same error.
    debug also pointing to
    "IF IJL1.FINDLAST THEN"

    any other solution?
  • ilovenavilovenav Member Posts: 9
    please help...
    [-o<
  • -Christoph-Christoph Member Posts: 7
    Hey,

    if you ONLY have records with "Source Code" = 'PHYSINVJNL' then, don't filter it. Otherwise you will get the error that the line already exists, when you already have data without the filtered source code in your Journal Line, because it's not part of your primary key.
    IJL1.SETRANGE("Source Code",'PHYSINVJNL');
    ..
    IJL_."Source Code" := 'PHYSINVJNL';
    


    I would write your FINDLAST like this (but yours should work as well)
    IF IJL1.FINDLAST THEN
      LineNo := IJL1."Line No." + 10000
    ELSE
      LineNo := 10000;
    


    Check if you really assign the correct values, which you filter on, to your new record.
  • ilovenavilovenav Member Posts: 9
    -Christoph wrote:
    Hey,

    if you ONLY have records with "Source Code" = 'PHYSINVJNL' then, don't filter it. Otherwise you will get the error that the line already exists, when you already have data without the filtered source code in your Journal Line, because it's not part of your primary key.
    IJL1.SETRANGE("Source Code",'PHYSINVJNL');
    ..
    IJL_."Source Code" := 'PHYSINVJNL';
    


    I would write your FINDLAST like this (but yours should work as well)
    IF IJL1.FINDLAST THEN
      LineNo := IJL1."Line No." + 10000
    ELSE
      LineNo := 10000;
    


    Check if you really assign the correct values, which you filter on, to your new record.


    the table is absolutely empty. whatever field that i use for setrange, it doesn't really mattered.
    and i use your code but still the same error.

    i used the same code with a little modification so that i can run in dataport nav 2009(classic)
    and its success with no error.

    thanks i appreciate your help, but i think i have to close this thread in one week if no one reply this again
    because i give up on this one.
  • VectorKVectorK Member Posts: 86
    Maybe you don't need to set filters before the FINDLAST
    (Because Line No. is the primary Key of the table)
  • ilovenavilovenav Member Posts: 9
    VectorK wrote:
    Maybe you don't need to set filters before the FINDLAST
    (Because Line No. is the primary Key of the table)

    thank you but still doesn't work.
    same error :cry:
  • VectorKVectorK Member Posts: 86
    If everything happens on the Import::OnBeforeInsertRecord() of the IJL_ table trigger, it seems that the "INSERT" instruction, have no sense there...
    Try to delete it
  • ilovenavilovenav Member Posts: 9
    VectorK wrote:
    If everything happens on the Import::OnBeforeInsertRecord() of the IJL_ table trigger, it seems that the "INSERT" instruction, have no sense there...
    Try to delete it

    thank you again but if i delete the "INSERT", microsoft dynamic nav is not responding and then crash
  • geordiegeordie Member Posts: 655
    So, at this point, why don't you set on Table element the property Temporary to Yes and fetch the records read from file in OnPostXMLport trigger?
    In this way you will be able to manage all the logic by C/AL code.
  • ilovenavilovenav Member Posts: 9
    geordie wrote:
    So, at this point, why don't you set on Table element the property Temporary to Yes and fetch the records read from file in OnPostXMLport trigger?
    In this way you will be able to manage all the logic by C/AL code.

    thank you but still...
    i put all the C/AL code in OnPostXMLport trigger, but its like no code at all.
    even if i just use "message('Test');"
    nothing show up.

    is this mean my Nav 2013 application have a problem?
  • ilovenavilovenav Member Posts: 9
    i closed this topic with no solution.

    thank you
Sign In or Register to comment.