Problem with inserting programmatically

tompynationtompynation Member Posts: 398
Hi, i modified the Sales List form: added an extra button "Create Transport Order"

This button should create a "Transport Order" for each selected Sales Header in the "Sales List" form...

Following code is behind the button:
CurrForm.SETSELECTIONFILTER(lv_SalesHeader);

IF lv_SalesHeader.FINDSET THEN BEGIN
    REPEAT
      /// Controleren of transport order reeds bestaat:
      lv_PurchHeader.RESET;
      lv_PurchHeader.SETRANGE(lv_PurchHeader."Linked Sales Order",lv_SalesHeader."No.");
      IF lv_PurchHeader.FINDFIRST THEN BEGIN
        MESSAGE(Text002,lv_PurchHeader."No.",lv_SalesHeader."No.");
        EXIT;
      END;

      lv_SalesHeader.TESTFIELD("Shipping Agent Code");
      lv_ShippingAgent.GET("Shipping Agent Code");

      lv_PurchHeader.INIT;
      lv_PurchHeader.VALIDATE("Document Type","Document Type"::Order);
      lv_PurchHeader.VALIDATE("No.",'');
      lv_PurchHeader.INSERT(TRUE);

      lv_PurchHeader.VALIDATE("Buy-from Vendor No.",lv_ShippingAgent."Vendor No.");
      lv_PurchHeader.VALIDATE("Transport Order",TRUE);
      lv_PurchHeader."Linked Sales Order" := lv_SalesHeader."No.";
      lv_PurchHeader.MODIFY(TRUE);
      COMMIT;

      lv_PurchLine.INIT;
      lv_PurchLine.VALIDATE("Document Type","Document Type"::Order);
      lv_PurchLine.VALIDATE("Document No.",lv_PurchHeader."No.");
      lv_PurchLine.VALIDATE("Line No.",10000);
      lv_PurchLine.INSERT(TRUE);

      lv_PurchLine.VALIDATE(Type,lv_PurchLine.Type::"Charge (Item)");
      lv_PurchLine.VALIDATE("No.",'TRANSPORT');
      lv_PurchLine.Quantity := 1;
      lv_PurchLine.MODIFY(TRUE);
      COMMIT;

      lv_SalesHeader."Linked Transport Order" := lv_PurchHeader."No.";
      lv_SalesHeader.MODIFY;

     //    FORM.RUNMODAL(50,lv_PurchHeader);
    
    UNTIL lv_SalesHeader.NEXT = 0;
END;

Now when just select 1 "Sales header" in the List Form the code works fine and the "Transport Order" gets created...

But the problem raises when i select more then one Sales Header.
For example when i select Sales order: 1023 & 1024

The transport order gets created for "Sales order" 1023

But it gives following error at the creation of the "Transport Order" for Sales Order 1024

You may not enter numbers manually. If you want to enter numbers manually, please activate Manual Nos. in No. Series I-ORD

But i'm not assigning numbers manually :?:

When i just select Sales Order 1023, press the "Create Transport Order" button, and then select
Sales Order 1024 and press the button. It creates them without any problem

So the problem raises as soon as it loops in the code...

Anyone knows why this is?

Answers

  • tompynationtompynation Member Posts: 398
    it works good when i activate the "Manual No's" inside the Number serie, but i dont get it why i have to do that???
  • DenSterDenSter Member Posts: 8,305
    It's common functionality for standard numbering series.
  • garakgarak Member Posts: 3,263
    Hi Tompynation.

    insead of
    lv_PurchHeader.validate("Document Type","Document Type"::Order);
    lv_PurchHeader.VALIDATE("No.",'');
    lv_PurchHeader.insert(true);
    

    use
    lv_PurchHeader.init;
    lv_PurchHeader."Document Type" := lv_PurchHeader."Document Type"::Order;;
    lv_PurchHeader."No." := '';
    lv_PurchHeader.insert(true);
    

    So, the default No Series will be used, and this is what you want ;-)
    Your mistake is, that you not use the "init" function and, that you validate the "No.".
    To understand it, read the code in No. - OnValidate and in OnInsert of table 38

    Regards
    Do you make it right, it works too!
Sign In or Register to comment.