Hello All,
I have one customization to be achieved where in the purchase line only the item with same vat. prod. posting group are to be allowed to insert.I have partially achieved the customization so far.The only problem I am facing is when I am inserting the item no. in second line it does not get validated and other fields are not populated automatically.I wrote the code in purchase order subform(50) page in the no. validate trigger and I called the function in that code.Following is the code I wrote:-
PurchLine := Rec;
IF Type = Type::Item THEN
CompareVatProdPostingGr(PurchLine);
CompareVatProdPostingGr(PurchLine); is the function I added.It has the following code:-
Item.RESET;
SETRANGE("Document Type","Document Type"::Order);
SETRANGE("Document No.","Document No.");
IF FINDFIRST THEN BEGIN
Item.SETRANGE("No.","No.");
IF Item.FINDFIRST THEN BEGIN
IF Item."VAT Prod. Posting Group" <> PurchaseLine."VAT Prod. Posting Group" THEN
ERROR(Text002);
END;
END;
I would really appreciate the help.I have been trying to figure it out for week.But getting no where.
*This post is locked for comments
Hi Sulav,
Always mark the relevant answer/(s) verified.
Thank You All for your help.Finally,it is solved now
Hi Sulav,
As per your post you are trying to give functionality to user wherein the user will select only those item where VAT prod posting group is same and this is simplify the VAT Invoice .
If that is the case I would suggest give one field for selection on Header for selection of VAT prod posting group and based on the value of that field display the item list for specific vat product posting group on subform/page
This will be simplify the process for user.
Hope this will help you.
Dear use whatsoever code in table trigger onvalidate as all other fields are validated over there. Writing code on page is not good idea when code is written in validate trigger of table. Reason why your fields are not getting populated.
Same code as suggested by Vishal and Nareshwar, Just replacing Item.RESET and FINDFIRST with GET Statement to reduce the line of codes.
IF Type = Type::Item THEN
CompareVatProdPostingGr(rec);
CompareVatProdPostingGr(PurchLineCurrent : Record "Purchase Line")
PurchLineFirstLine.SETRANGE("Document Type",PurchLine."Document Type"::Order);
PurchLineFirstLine.SETRANGE("Document No.",PurchLine."Document No.");
PurchLineFirstLine.SETRANGE(Type,PurchLineFirstLine.Type::Item);
IF PurchLineFirstLine.FIND('-') THEN BEGIN
IF Item.GET(PurchLineCurrent."No.") THEN;
IF Item."VAT Prod. Posting Group" <> PurchLineFirstLine."VAT Prod. Posting Group" THEN
ERROR(Text002);
END;
Hi Vishal,
Thank you for simplifying the code. Your solution looks more cleaner ;)
Try this code on No._OnValidate.
IF Type = Type::Item THEN
CompareVatProdPostingGr(rec);
CompareVatProdPostingGr(PurchLineCurrent : Record "Purchase Line")
Item.Reset;
PurchLineFirstLine.SETRANGE("Document Type",PurchLine."Document Type"::Order);
PurchLineFirstLine.SETRANGE("Document No.",PurchLine."Document No.");
PurchLineFirstLine.SETRANGE(Type,PurchLineFirstLine.Type::Item);
IF PurchLineFirstLine.FIND('-') THEN BEGIN
Item.SETRANGE("No.",PurchLineCurrent."No.");
IF Item.FINDFIRST THEN
IF Item."VAT Prod. Posting Group" <> PurchLineFirstLine."VAT Prod. Posting Group" THEN
ERROR(Text002);
END;
*****
CompareVatProdPostingGr(PurchLine); is the function I added.It has the following code:-
Item.RESET;
PurchLine1stLine.SETCURRENTKEY("Line No.");
PurchLine1stLine.SETRANGE("Document Type","Document Type"::Order);
PurchLine1stLine.SETRANGE("Document No.","Document No.");
IF PurchLine1stLine.FIND('-') THEN
BEGIN
PurchLine.SETRANGE("Document Type","Document Type"::Order);
PurchLine.SETRANGE("Document No.","Document No.");
PurchLine.SETRANGE("Line No.", "Line No.");
IF PurchLine.FIND('-') THEN
BEGIN
Item.SETRANGE("No.", PurchLine."No.");
IF Item.FIND('-') THEN
BEGIN
IF Item."VAT Prod. Posting Group" <> PurchLine1stLine."VAT Prod. Posting Group" THEN
ERROR(Text002);
END;
END;
END;
Hi,
Try this code. Check the highlighted. The highlighted code will find the first record of the purchase line and inside the IF, it finds the current line and compares the VAT Prod. Posting Group. If it is the first line of the document, it does nothing. But you probably shouldn't write this in No. On Validate() because that this time, no Line No. is inserted. Try On Modify() or On Insert() on the Purchase Line Table.
Tried those code but its not throwing me an error message when I insert the item with the different vat. prod. posting group than the first line
Hi,
The second line didn't get triggered because you are filtering the Line No. I guess. Try this code.
*****
CompareVatProdPostingGr(PurchLine); is the function I added.It has the following code:-
Item.RESET;
PurchLine.SETRANGE("Document Type","Document Type"::Order);
PurchLine.SETRANGE("Document No.","Document No.");
PurchLine.SETRANGE("Line No.", "Line No.");
IF PurchLine.FIND('-') THEN BEGIN
Item.SETRANGE(PurchLine."No.","No.");
IF Item.FINDFIRST THEN BEGIN
IF Item."VAT Prod. Posting Group" <> PurchaseLine."VAT Prod. Posting Group" THEN
ERROR(Text002);
END;
END;
PurchLine is a record variable of Table Purchase Line.
Hope it helps.
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,240 Super User 2024 Season 2
Martin Dráb 230,149 Most Valuable Professional
nmaenpaa 101,156