I want to create multiple PO's with one button

Demonic240Demonic240 Member Posts: 65
I mentioned earlier in a previous thread that I am working on en expense form. One of the objectives of this form is to create a PO for each employee at once. I can create one PO at a time, however if I try to create multiple ones at once i get this message: You may not enter numbers manually. If you want to enter numbers manually, please activate Manual Nos. in No. Series P-ORD. I am using an InitSeries command within a repeat to create the PO number. Please help!

Comments

  • AlbertvhAlbertvh Member Posts: 516
    Hi,

    Are you clearing the PO Header record before you update the fields on it?

    eg.

    CLEAR(POHeader);
    POHeader.INIT;
    ...
    ...
    POHeader.INSERT

    Albert
  • Demonic240Demonic240 Member Posts: 65
    No I'm not, let me try that.
  • Demonic240Demonic240 Member Posts: 65
    Just tried it out. That worked for creating new PO Headers. I also tried adding a CLEAR(PL) to clear the Purchase Lines but each PO is showing the data for the first one.
  • AlbertvhAlbertvh Member Posts: 516
    Hi

    Are you doing something like this
    IF Emp.FINDSET THEN
      REPEAT
         CLEAR(PO);
         PO.INIT;
         PO."Document Type" := PO."Document Type"::Order; 
         PO.INSERT(TRUE); // This will get your number
         fill in other fields info
         PO.MODIFY;
         CLEAR(PL);
         PL.INIT;
         PL."Document Type" := PO."Document Type";
         PL."Document No." := PO."No.";
         fill in other fields info
         PL.INSERT;
      UNTIL Emp.NEXT = 0;
    

    Hope this helps

    Albert
  • Demonic240Demonic240 Member Posts: 65
    This is what I have:
    EETOLD:='';
    Rec.SETCURRENTKEY("Employee No.");
    Rec.SETFILTER(Status,'<>posted');
    IF FINDFIRST THEN BEGIN 
     
      REPEAT
        IF Rec."Employee No."<>EETOLD {AND (EETOLD<>'')} THEN BEGIN
          CLEAR(PH);
          PurchSetup.GET;
          PH.INIT;
               NoSeriesMgnt.InitSeries('P-ORD','P-ORD',WORKDATE,PH."No.",PH."No. Series");
            PH."Document Type":=PH."Document Type"::Order;
            PH.VALIDATE("Buy-from Vendor No.",Rec."Employee No.");
            (DATA)
          PH.INSERT;
          PH.MODIFY;
         
    
          CLEAR(PL);
          LineNo:=0;
          REPEAT
          EmployeeExpense3.SETFILTER("Employee No.",FORMAT(Rec."Employee No."));
            Vend.GET("Employee No.");
              EmployeeName:=Vend.Name;
            Employee.GET("Employee No.");
              "Div/Dep":=Employee."Global Dimension 1 Code";
           PL.INIT;
            LineNo+=1000;
            PL.FINDFIRST;
            PL.VALIDATE("Line No.",LineNo);
            PL."Document No.":=PH."No.";
            PL.VALIDATE("Document Type",PL."Document Type"::Order);
            PL.VALIDATE(Type,PL.Type::"G/L Account");
            PL.VALIDATE("No.",EmployeeExpense3."O/H Account No.");
           (DATA) 
            IF Amount<>0 THEN
               PL.INSERT;
            PL.VALIDATE("Shortcut Dimension 1 Code","Div/Dep");
            IF EmployeeExpense3."Job No." <>'' THEN
              PL.VALIDATE("Job No.",EmployeeExpense3."Job No.");
          MODIFY;
          UNTIL EmployeeExpense3.NEXT=0;
        END;
           EETOLD:=Rec."Employee No.";
      UNTIL Rec.NEXT=0;
    
  • AlbertvhAlbertvh Member Posts: 516
    I have had a look at your code and have changed it
    EETOLD:=''; 
    Rec.SETCURRENTKEY("Employee No."); 
    Rec.SETFILTER(Status,'<>posted'); 
    IF FINDFIRST THEN
      REPEAT
        IF Rec."Employee No."<>EETOLD {AND (EETOLD<>'')} THEN BEGIN 
          CLEAR(PH); 
          PH.INIT; 
          // Don't need this line
          //PurchSetup.GET;
          //NoSeriesMgnt.InitSeries('P-ORD','P-ORD',WORKDATE,PH."No.",PH."No. Series");
          PH."Document Type":=PH."Document Type"::Order;
          PH.INSERT(TRUE); // Will exit the OnInsert trigger and get the next PO No. for you
          PH.VALIDATE("Buy-from Vendor No.",Rec."Employee No.");
          (DATA)
          PH.MODIFY; 
          
    
          CLEAR(PL); 
          PL.SETRANGE("Document Type" := PH."Document Type";
          PL.SETRANGE("Document No.",PH."no.");
          IF PL.FINDLAST THEN
            LineNo := PL."Line No.";
          LineNo += 10000;
    
            EmployeeExpense3.SETFILTER("Employee No.",FORMAT(Rec."Employee No."));
          IF EmployeeExpense3.FINDSET THEN
    
          REPEAT 
            Vend.GET("Employee No.");
            EmployeeName:=Vend.Name;
            Employee.GET("Employee No."); 
            "Div/Dep":=Employee."Global Dimension 1 Code";
            PL.INIT;
            PL."Document Type":=PL."Document Type"::Order;
            PL."Document No.":=PH."No."; 
            PL."Line No.":=LineNo;
            PL.Type:=PL.Type::"G/L Account";
            PL.VALIDATE("No.",EmployeeExpense3."O/H Account No."); 
            (DATA)
            PL.VALIDATE("Shortcut Dimension 1 Code","Div/Dep"); 
            IF EmployeeExpense3."Job No." <>'' THEN 
              PL.VALIDATE("Job No.",EmployeeExpense3."Job No."); 
            IF Amount<>0 THEN BEGIN
              PL.INSERT;
              LineNo+=10000;
            END;
          UNTIL EmployeeExpense3.NEXT=0; 
        END; 
        EETOLD:=Rec."Employee No.";
      UNTIL Rec.NEXT=0;
    
    

    Hope this gets you going. I'm not quite sure what you're trying to achive.
    Do you want one PO Header for each employee and then multiple lines for each expense?


    Albert
  • AlbertvhAlbertvh Member Posts: 516
    Had a little think about this :-k
    Maybe you want to do this
    EETOLD:=''; 
    Rec.SETCURRENTKEY("Employee No."); 
    Rec.SETFILTER(Status,'<>posted'); 
    IF FINDFIRST THEN 
      REPEAT 
        IF Rec."Employee No."<>EETOLD THEN BEGIN
          CLEAR(PH); 
          PH.INIT; 
          // Don't need this line 
          //PurchSetup.GET; 
          //NoSeriesMgnt.InitSeries('P-ORD','P-ORD',WORKDATE,PH."No.",PH."No. Series"); 
          PH."Document Type":=PH."Document Type"::Order; 
          PH.INSERT(TRUE); // Will exit the OnInsert trigger and get the next PO No. for you 
          PH.VALIDATE("Buy-from Vendor No.",Rec."Employee No."); 
          (DATA) 
          PH.MODIFY; 
          LineNo := 0;
        END;
    
        CLEAR(PL);
        PL.SETRANGE("Document Type" := PH."Document Type";
        PL.SETRANGE("Document No.",PH."no.");
        IF PL.FINDLAST THEN
          LineNo := PL."Line No.";
        LineNo += 10000;
    
        EmployeeExpense3.SETFILTER("Employee No.",FORMAT(Rec."Employee No."));
        IF EmployeeExpense3.FINDSET THEN
          REPEAT 
            Vend.GET("Employee No."); 
            EmployeeName:=Vend.Name; 
            Employee.GET("Employee No."); 
            "Div/Dep":=Employee."Global Dimension 1 Code"; 
            PL.INIT; 
            PL."Document Type":=PL."Document Type"::Order; 
            PL."Document No.":=PH."No."; 
            PL."Line No.":=LineNo; 
            PL.Type:=PL.Type::"G/L Account"; 
            PL.VALIDATE("No.",EmployeeExpense3."O/H Account No."); 
            (DATA) 
            PL.VALIDATE("Shortcut Dimension 1 Code","Div/Dep"); 
            IF EmployeeExpense3."Job No." <>'' THEN 
              PL.VALIDATE("Job No.",EmployeeExpense3."Job No."); 
            IF Amount<>0 THEN BEGIN 
              PL.INSERT; 
              LineNo+=10000; 
            END; 
          UNTIL EmployeeExpense3.NEXT=0; 
        END; 
        EETOLD:=Rec."Employee No."; 
      UNTIL Rec.NEXT=0; 
    

    Hope this helps [-o<

    Albert
  • Demonic240Demonic240 Member Posts: 65
    edited 2007-10-03
    Thanks. I'll try that out. What I want is 1 Header for each employee and a line for each expense.
  • Demonic240Demonic240 Member Posts: 65
    Ok, just tried out the code. It's working much better in terms of separating the lines for each employee. The issue I'm running into now is that each line for each employee is repeated three times. Not right after each other, but all of the lines will be inputed and then re-inputed twice more.
Sign In or Register to comment.