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)

Only Item with same vat. prod. posting group to be allowed to insert in purchase line

(0) ShareShare
ReportReport
Posted on by 12

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

I have the same question (0)
  • Amol Salvi Profile Picture
    18,698 on at

    By looking at your code it seems user is entering VAT prod posting group in purchase line which you are checking with item master is it ?

  • Sulav Thapaliya Profile Picture
    12 on at

    No,Vat. Prod. Posting Group is validated automatically from Item's vat. prod. posting gr.

    I am just comparing it with first line's vat. prod posting group.If it is different from first line then it should throw me an error message.I have achieved the customization but only problem is that when I insert the item no. in second line they are not validated and other fields are not populated.If I comment out these codes then its working fine but when I am using the code.Its not working.I dont know why ?

  • Suggested answer
    Nareshwar Raju Vaneshwar Profile Picture
    5,596 on at

    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.

  • Sulav Thapaliya Profile Picture
    12 on at

    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

  • Suggested answer
    Nareshwar Raju Vaneshwar Profile Picture
    5,596 on at

    *****

    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.

  • Verified answer
    Community Member Profile Picture
    on at

    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;

  • Suggested answer
    Nareshwar Raju Vaneshwar Profile Picture
    5,596 on at

    Hi Vishal,

    Thank you for simplifying the code. Your solution looks more cleaner ;)

  • Suggested answer
    RockwithNav Profile Picture
    8,631 Super User 2025 Season 2 on at

    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;

  • Suggested answer
    Ashwini Tripathi Profile Picture
    4,624 on at

    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.

  • Suggested answer
    Amol Salvi Profile Picture
    18,698 on at

    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.

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)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans