Add line to purchase order when user added vendor no.

rodrigopuelmarodrigopuelma Member Posts: 15
Hello,

I'm having an issue that I cannot resolve and I was hoping someone who's had a similar issue can help me with a possible solution.

A customer needs to add automatically a line to a purchase order where line Type is of "G/L Account". The customer creates a new purchase order and then selects a vendor no. I have constructed a codeunit which inserts a line to the purchase order. But when the field "No." is validated I get an error informing that the purchase order vendor no. is missing. I understand that if I put my code in for example the function OnValidate, in both the form or the table, the actual modification of the field "Buy-from Vendor No." has not been made yet and therefore I get this error. The problem is where do I call my codeunit to be able to add a line which calls the validation function of the field "No." when "Buy-from Vendor No." has been changed but after the change has been saved?

I have tried to use COMMIT and to call my codeunits from all the triggers of the field "Buy-from Vendor No." in the form, and also the forms OnModify-function, and the table Purchase Header's Modify-function and the fields VALIDATE-function.

Comments

  • kinekine Member Posts: 12,562
    It is why it is not good to modify other tables from onvalidate trigger (another is, that there could be inconsystencies). Try to describe, what you want to do from the user point of view. May be there is totally different way how to solve it. Inserting line when creating header is not good process.
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • bstnalmbstnalm Member Posts: 25
    If it is not compulsory to be automated, can the standard Copy Document function helps?
  • dansdans Member Posts: 148
    one way to do it is to disable 'insert' on the form and create a button. When you press the button, you go to a new form where you can select the vendor no. After that, NAV automatically insert the purchase header (with vendor no.) and the purchase lines.
    Microsoft Certified IT Professional for Microsoft Dynamics NAV

    Just a happy frood who knows where his towel is
  • gsmakhijagsmakhija Member Posts: 2
    Hi,

    Just create a dummy vendor (i.e. Order in Process) without setup

    Then insert lines with your codes & when actual vendor will be selected in Buy-from Vendor No. lines get updated with new vendor No.
  • SavatageSavatage Member Posts: 7,142
    A Command Button or Menu Item can add a line to a po easily.
    PurchSetup."Exchange Account (G/L)" = field added to setup table to it can changed in the future if need be. Don't like hard coding.
    OnPush()
    IF Status = Status::Open THEN BEGIN
      InvSetup.GET;
      Purchline.RESET;
      Purchline.SETRANGE(Purchline."Document Type","Document Type");
      Purchline.SETRANGE(Purchline."Document No.","No.");
       IF Purchline.FIND('+') THEN BEGIN
         Purchline."Line No." := Purchline."Line No."+ 10000;
         Purchline.Type := Purchline.Type::"Account (G/L)";
         Purchline.VALIDATE(Purchline."No.",PurchSetup."Exchange Account (G/L)");
         Purchline.VALIDATE(Purchline.Quantity,1);
         Purchline.INSERT;
        END;
    END ELSE BEGIN
      MESSAGE('Purchase Order %1 must be open!',"No.");
    END;
    
Sign In or Register to comment.