This function is meant to write a record into the Purchase comment line table however I keep getting an error
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 think it it issue if reset .Check your code as try to debug the code using debugger.
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.
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;
Send us the code you have finally used.
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??
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.
By using the above code ? when you compile where is the cursor highlight ?
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.
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;
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?
Sohail Ahmed
2
mmv
2
Amol Salvi
2