Skip to main content

Notifications

Microsoft Dynamics NAV (Archived)

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

Posted on by 2

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

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Only Item with same vat. prod. posting group to be allowed to insert in purchase line

    Hi Sulav,

    Always mark the relevant answer/(s) verified.

  • Sulav Thapaliya Profile Picture
    Sulav Thapaliya 2 on at
    RE: Only Item with same vat. prod. posting group to be allowed to insert in purchase line

    Thank You All for your help.Finally,it is solved now

  • Suggested answer
    Amol Salvi Profile Picture
    Amol Salvi 18,694 on at
    RE: Only Item with same vat. prod. posting group to be allowed to insert in purchase line

    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.

  • Suggested answer
    Ashwini Tripathi Profile Picture
    Ashwini Tripathi 4,624 on at
    RE: Only Item with same vat. prod. posting group to be allowed to insert in purchase line

    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
    RockwithNav Profile Picture
    RockwithNav 6,562 on at
    RE: Only Item with same vat. prod. posting group to be allowed to insert in purchase line

    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
    RE: Only Item with same vat. prod. posting group to be allowed to insert in purchase line

    Hi Vishal,

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

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Only Item with same vat. prod. posting group to be allowed to insert in purchase line

    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
    RE: Only Item with same vat. prod. posting group to be allowed to insert in purchase line

    *****

    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.

  • Sulav Thapaliya Profile Picture
    Sulav Thapaliya 2 on at
    RE: Only Item with same vat. prod. posting group to be allowed to insert in purchase line

    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
    RE: Only Item with same vat. prod. posting group to be allowed to insert in purchase 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.

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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Complete!

🔔 Be sure to subscribe to the new forums you are interested in to stay up to date! 🔔

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,113 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 229,918 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans