Listing out item from BOM in Item Reclass Journal

lavanyaballurgilavanyaballurgi Member Posts: 235
Hey Experts,

I created a button in ITEM RECLASS where the user will fill the prod. order & when press this button it will list out the items present in the Prod. Order Component table of that prod order. But I am getting some error. Kindly help

CODE -


line:=10000;

ItemJournal.RESET;
ItemJournal.SETRANGE("Journal Template Name",'Transfer');
ItemJournal.SETRANGE("Journal Batch Name",'ISSUE');
ItemJournal.SETRANGE("Document No.","Document No.");
ItemJournal.SETRANGE("Posting Date","Posting Date");
ItemJournal.SETRANGE("Entry Type",4);

Prodordercomponent.SETRANGE("Prod. Order No.","Prod. Order No.");
IF Prodordercomponent.FINDFIRST THEN BEGIN
REPEAT
ItemJournal."Journal Template Name" := 'Transfer';
ItemJournal."Journal Batch Name" := 'ISSUE';
ItemJournal."Line No." := line;
ItemJournal."Document No." := "Document No.";
ItemJournal."Document Date" := "Document Date";
ItemJournal."Posting Date" := "Posting Date";
ItemJournal."External Document No." := "External Document No.";
ItemJournal."Entry Type" := "Entry Type";
ItemJournal."Location Code" := "Location Code";
ItemJournal.VALIDATE("Item No.",POC."Item No.");
ItemJournal.VALIDATE("Unit of Measure Code",POC."Unit of Measure Code");
ItemJournal.VALIDATE(Quantity,POC."Remaining Quantity");
ItemJournal.Description := POC.Description;
ItemJournal.MODIFY;
ItemJournal.INSERT;
line := line+10000;
UNTIL Prodordercomponent.NEXT = 0;
END;



And the error is

"The Item Journal Line already exists.

Identification fields and values:

Journal Template Name='TRANSFER',Journal Batch Name='ISSUE',Line No.='10000'"

Answers

  • mohana_cse06mohana_cse06 Member Posts: 5,503
    And the error is

    "The Item Journal Line already exists.

    Identification fields and values:

    Journal Template Name='TRANSFER',Journal Batch Name='ISSUE',Line No.='10000'"

    The error message is very clear that you already have lines in table..
  • udayrmerudayrmer Member Posts: 171
    You shold write a code that find out last line no. in the Item Journal Line with the batch name & Template name.
    then increment it by 10000 for every entry you are inserting.
    Uday Mer | MS Dynamics NAV Techno-Functional Consultant
  • lavanyaballurgilavanyaballurgi Member Posts: 235
    so only i am incrementing it by 10000...
  • lavanyaballurgilavanyaballurgi Member Posts: 235
    @Udayrmer - I thought of begining it with line no. 10000 only so didnt added that. By the way if the ITEM RECLASS is empty then my code should work right?
  • udayrmerudayrmer Member Posts: 171
    Yes but best practice is to get last line no.

    as well as why you are using both modify & Insert, please use only Insert.

    ItemJournal.MODIFY;//remove it
    ItemJournal.INSERT;
    Uday Mer | MS Dynamics NAV Techno-Functional Consultant
  • lavanyaballurgilavanyaballurgi Member Posts: 235
    Oh sorry I forgot to remove "Modify". I was actually trying to see if using MODIFY would overright the lines :(
    And how to find out the last line no. used?
  • udayrmerudayrmer Member Posts: 171
    ItemJournal.RESET;
    ItemJournal.SETRANGE("Journal Template Name",'Transfer');
    ItemJournal.SETRANGE("Journal Batch Name",'ISSUE');
    IF ItemJournal.FINDLAST THEN
    Line := ItemJournal."Line No."
    ELSE
    Line := 0;
    Uday Mer | MS Dynamics NAV Techno-Functional Consultant
  • lavanyaballurgilavanyaballurgi Member Posts: 235
    Still same error ... :-k
  • udayrmerudayrmer Member Posts: 171
    Please give me your whole code.
    Uday Mer | MS Dynamics NAV Techno-Functional Consultant
  • lavanyaballurgilavanyaballurgi Member Posts: 235
    Here is it.

    <Control1000000005> - OnPush()

    ToIJ.RESET;
    ToIJ.SETRANGE("Journal Template Name",'Transfer');
    ToIJ.SETRANGE("Journal Batch Name",'ISSUE');
    ToIJ.SETRANGE("Document No.","Document No.");
    ToIJ.SETRANGE("Posting Date","Posting Date");
    ToIJ.SETRANGE("Entry Type",4);
    IF ToIJ.FINDLAST THEN
    line := ToIJ."Line No."
    ELSE
    line := 0;

    POC.SETRANGE("Prod. Order No.","Prod. Order No.");
    IF POC.FINDFIRST THEN BEGIN
    REPEAT
    ToIJ."Journal Template Name" := 'Transfer';
    ToIJ."Journal Batch Name" := 'ISSUE';
    ToIJ."Line No." := line;
    ToIJ."Document No." := "Document No.";
    ToIJ."Document Date" := "Document Date";
    ToIJ."Posting Date" := "Posting Date";
    ToIJ."External Document No." := "External Document No.";
    ToIJ."Entry Type" := "Entry Type";
    ToIJ."Location Code" := "Location Code";
    ToIJ.VALIDATE("Item No.",POC."Item No.");
    ToIJ.VALIDATE("Unit of Measure Code",POC."Unit of Measure Code");
    ToIJ.VALIDATE(Quantity,POC."Remaining Quantity");
    ToIJ.Description := POC.Description;
    ToIJ.MODIFY;
    ToIJ.INSERT;
    line := line+10000;
    UNTIL POC.NEXT = 0;
    END;
  • mohana_cse06mohana_cse06 Member Posts: 5,503
    Use
    ItemJournal.RESET;
    ItemJournal.SETRANGE("Journal Template Name",'Transfer');
    ItemJournal.SETRANGE("Journal Batch Name",'ISSUE');
    IF ItemJournal.FINDLAST THEN
      Line := ItemJournal."Line No." + 10000
    ELSE
      Line := 10000;
    

    Remove Line := 10000; from your code..
  • mohana_cse06mohana_cse06 Member Posts: 5,503
  • udayrmerudayrmer Member Posts: 171
    Modify in below way,

    ToIJ.RESET;
    ToIJ.SETRANGE("Journal Template Name",'Transfer');
    ToIJ.SETRANGE("Journal Batch Name",'ISSUE');
    IF ToIJ.FINDLAST THEN
    line := ToIJ."Line No."+10000
    ELSE
    line := 10000;

    POC.SETRANGE("Prod. Order No.","Prod. Order No.");
    IF POC.FINDFIRST THEN BEGIN
    REPEAT
    ToIJ.INIT;
    ToIJ."Journal Template Name" := 'Transfer';
    ToIJ."Journal Batch Name" := 'ISSUE';
    ToIJ."Line No." := line;
    ToIJ."Document No." := "Document No.";
    ToIJ."Document Date" := "Document Date";
    ToIJ."Posting Date" := "Posting Date";
    ToIJ."External Document No." := "External Document No.";
    ToIJ."Entry Type" := ToIJ."Entry Type"::Transfer;
    ToIJ."Location Code" := "Location Code";
    ToIJ.VALIDATE("Item No.",POC."Item No.");
    ToIJ.VALIDATE("Unit of Measure Code",POC."Unit of Measure Code");
    ToIJ.VALIDATE(Quantity,POC."Remaining Quantity");
    ToIJ.Description := POC.Description;
    ToIJ.INSERT;
    line := line+10000;
    UNTIL POC.NEXT = 0;
    END;
    Uday Mer | MS Dynamics NAV Techno-Functional Consultant
  • mohana_cse06mohana_cse06 Member Posts: 5,503
    you can use Report 5405 Calc. Consumption..
  • lavanyaballurgilavanyaballurgi Member Posts: 235
    This one worked... Thank Mohana & Udayrmer... combining your expert opinion i could get this ...

    IF ItemJournal.FINDLAST THEN
    line := ItemJournal."Line No."+ 10000
    ELSE
    line := 10000;
Sign In or Register to comment.