Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Microsoft Dynamics NAV (Archived)

Writing records to a Comment Table

(0) ShareShare
ReportReport
Posted on by

This function is meant to write a record into the Purchase comment line table however I keep getting an error

107.PNG

This is my code written on the Purchase Line Table 


IF QuantityChange THEN BEGIN
IF PurchHeader."Released Once" THEN BEGIN
IF Quantity <> xRec.Quantity THEN BEGIN
recPurchCommentLine.RESET;
recPurchCommentLine.SETRANGE("Document Type", "Document Type");
recPurchCommentLine.SETRANGE("No.", "Document No.");
recPurchCommentLine.SETRANGE("Document Line No.", "Line No.");
recPurchCommentLine.SETRANGE("Comment Type", recPurchCommentLine."Comment Type"::PurchChange);
IF recPurchCommentLine2.FINDLAST THEN
recPurchCommentLine."Line No." := recPurchCommentLine2."Line No."
ELSE
recPurchCommentLine."Line No." := 1000;
recPurchCommentLine."Comment Type" := recPurchCommentLine."Comment Type"::PurchChange;
recPurchCommentLine.Comment :=
STRSUBSTNO(
Text107,
"Line No.",
xRec.Quantity,
Quantity);
recPurchCommentLine.Date := WORKDATE;
recPurchCommentLine.INSERT;
END;
END;
END ELSE

 

All feedback is appreciated!

*This post is locked for comments

  • Suggested answer
    Amol Salvi Profile Picture
    18,698 on at
    RE: Writing records to a Comment Table

    I think it it issue if reset .Check your code as try to debug the code using debugger.

  • Suggested answer
    IshwarSharma Profile Picture
    729 on at
    RE: Writing records to a Comment Table

    The Insert might not be working due to QuantityChange and Purchheader."Released Once" Booleans. Are you sure that your debugger is going till Insert function in your code?

    Also, please check the data in the correct company. Just reassuring.

  • Verified answer
    Community Member Profile Picture
    on at
    RE: Writing records to a Comment Table

    I Have Moved it over to a codeunit.

    CreateCPurchaseOrderComment(QuantityChange : Boolean;DateChange : Boolean;Purchheader : Record "Purchase Header";recPurchLine : Record "Purchase Line";xRec : Record "Purchase Line")

    IF QuantityChange THEN BEGIN

     IF Purchheader."Released Once" THEN BEGIN

       IF recPurchLine.Quantity <> xRec.Quantity THEN BEGIN

         recPurchCommentLine.INIT;

         {recPurchCommentLine."Document Type" := "Document Type";

         recPurchCommentLine."No." := "Document No.";

         recPurchCommentLine."Document Line No." := "Line No.";}

         recPurchCommentLine.RESET;

         recPurchCommentLine.SETRANGE("Document Type",recPurchLine."Document Type");

         recPurchCommentLine.SETRANGE("No.", recPurchLine."Document No.");

         recPurchCommentLine.SETRANGE("Document Line No.", recPurchLine."Line No.");

         recPurchCommentLine.SETRANGE("Comment Type", recPurchCommentLine."Comment Type"::PurchChange);

         IF recPurchCommentLine2.FINDLAST THEN

           intLineNo := recPurchCommentLine."Line No." + 10000

         ELSE

           intLineNo := 10000;

           recPurchCommentLine."Comment Type" := recPurchCommentLine."Comment Type"::PurchChange;

           recPurchCommentLine.Comment :=  

           STRSUBSTNO(

             Text107,

             recPurchLine."Line No.",

             xRec.Quantity,

             recPurchLine.Quantity);

           recPurchCommentLine.Date := WORKDATE;

           recPurchCommentLine.INSERT(TRUE);

       END;

     END;

  • Suggested answer
    Suresh Kulla Profile Picture
    47,789 on at
    RE: Writing records to a Comment Table

    Send us the code you have finally used.

  • Community Member Profile Picture
    on at
    RE: Writing records to a Comment Table

    Ok so I've made the changes and i'm no longer receiving the error.  However I ran through debugger and it goes throgh the code as it should, but when I check the comment table there's no entry. As if the INSERT isnt working??

  • Suggested answer
    IshwarSharma Profile Picture
    729 on at
    RE: Writing records to a Comment Table

    I hope there isn't any customized code in Purch. Comment Line table in your database. Instead of validate try add these lines after INIT,

    recPurchCommentLine."Document Type" := "Document Type";

    recPurchCommentLine."No." := "Document No.";

    recPurchCommentLine."Document Line No." := "Line No.";

    Adding this code might fix the error. But also check why you are getting this error, try to debug the code and let us know.

  • Suggested answer
    Suresh Kulla Profile Picture
    47,789 on at
    RE: Writing records to a Comment Table

    By using the above code ? when you compile where is the cursor highlight ?

  • Community Member Profile Picture
    on at
    RE: Writing records to a Comment Table

    It's a function which is called when the Qty on a  purchase Line is changed.

    I'm getting the "A field from a record variable was expected." when trying to add the Validate Lines.

  • Suggested answer
    Suresh Kulla Profile Picture
    47,789 on at
    RE: Writing records to a Comment Table

    use the below code and declare a variable of type integer LineNo.

    F PurchHeader."Released Once" THEN BEGIN

    IF Quantity <> xRec.Quantity THEN BEGIN

    recPurchCommentLine.RESET;

    recPurchCommentLine.SETRANGE("Document Type", "Document Type");

    recPurchCommentLine.SETRANGE("No.", "Document No.");

    recPurchCommentLine.SETRANGE("Document Line No.", "Line No.");

    recPurchCommentLine.SETRANGE("Comment Type", recPurchCommentLine."Comment Type"::PurchChange);

    IF recPurchCommentLine.FINDLAST

       LineNo := recPurchCommentLine."Line No." + 10000

    ELSE

       LineNo:= 10000;

    recPurchCommentLine.INIT;

    recPurchCommentLine."Document Type" := "Document Type";

    recPurchCommentLine."No." := "Document No.";

    recPurchCommentLine."Document Line No." := "Line No.";

    recPurchCommentLine."Line No." := LineNo;    

    recPurchCommentLine."Comment Type" := recPurchCommentLine."Comment Type"::PurchChange;

    recPurchCommentLine.Comment :=

    STRSUBSTNO(

    Text107,

    "Line No.",

    xRec.Quantity,

    Quantity);

    recPurchCommentLine.Date := WORKDATE;

    recPurchCommentLine.INSERT;

    END;

    END;

  • Suggested answer
    IshwarSharma Profile Picture
    729 on at
    RE: Writing records to a Comment Table

    Please add the following code as well,

    recPurchCommentLine.Validate("Document No.","Document No.");

    recPurchCommentLine.Validate("No.","No.");

    recPurchCommentLine.Validate("Document Line No.","Line No.");

    Add this code after INIT. Is this a function OR have you written this code in a particular trigger in Purchase Line Table?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Leaderboard > Microsoft Dynamics NAV (Archived)

#1
Sohail Ahmed Profile Picture

Sohail Ahmed 2

#1
mmv Profile Picture

mmv 2

#1
Amol Salvi Profile Picture

Amol Salvi 2

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans