web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

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

I have the same question (0)
  • Suggested answer
    IshwarSharma Profile Picture
    729 on at

    Please correct your code and try this,

    recPurchCommentLine.INIT;  //You must INIT the record variable (of the table) before inserting new records in it.

    IF recPurchCommentLine2.FINDLAST THEN

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

    ELSE

    recPurchCommentLine."Line No." := 10000;

    Assign the correct Line No. as shown in the code above. Hence, if records already exist in the table then you need to iterate the new record you're inserting by 10K.

  • Community Member Profile Picture
    on at

    Thank you, I've made these adjustments but still getting the error.

    108.PNG

    Is this possibly due to records in my table rather then the code?? 

    IF QuantityChange THEN BEGIN

     IF PurchHeader."Released Once" THEN BEGIN

       IF Quantity <> xRec.Quantity THEN BEGIN

       CLEAR(recPurchCommentLine);

       recPurchCommentLine.INIT;

         recPurchCommentLine.RESET;

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

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

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

         IF recPurchCommentLine2.FINDLAST THEN

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

         ELSE

           recPurchCommentLine."Line No." := 10000;

           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

  • Suggested answer
    IshwarSharma Profile Picture
    729 on at

    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?

  • Suggested answer
    Suresh Kulla Profile Picture
    50,245 Super User 2025 Season 2 on at

    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;

  • Community Member Profile Picture
    on at

    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
    50,245 Super User 2025 Season 2 on at

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

  • Suggested answer
    IshwarSharma Profile Picture
    729 on at

    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.

  • Community Member Profile Picture
    on at

    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
    Suresh Kulla Profile Picture
    50,245 Super User 2025 Season 2 on at

    Send us the code you have finally used.

  • Verified answer
    Community Member Profile Picture
    on at

    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;

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics NAV (Archived)

#1
HoangNam Profile Picture

HoangNam 7

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans