Problems with new Batch Production Post Function

alsolalsol Member Posts: 243
Hello there,
A customer uses Swiss Production Module but does more assembling than real production. He asked me for a new function on the sales order which should be able to post all production orders related to the actual sales order. Of course this should be status driven, so a the end the production orders should be on Archived.

I developed this function and it work very well as long I have only one sales line with a production order. As soon I have more than one, the Post Production Codeunit comes up with an error when posting the second production order saying "Value Entry XYZ already exists".

This is the code I developed behind a button on the sales order form:
ProdOrderHead.RESET;
ProdOrderHead.SETRANGE("Sales Order No.","No.");
ProdOrderHead.SETFILTER(Status, '<>Archived');
IF ProdOrderHead.FIND('-') THEN BEGIN
  IF NOT CONFIRM(Text50012,FALSE) THEN
    EXIT;

  REPEAT
    //Save No. of Production order and Rec
    ProdOrderNo := ProdOrderHead.Number;
    ProdOrderHead2 := ProdOrderHead;

    //Save current status
    ProdNewStatus := ProdOrderHead.Status;
    
    WHILE ProdNewStatus < 5 DO BEGIN

      ProdOrderHead2.RESET;
      ProdOrderHead2.GET(ProdOrderNo);

      //Set new status
      ProdNewStatus := ProdNewStatus + 1;
      
      //Post production if new status = Completed
      IF ProdNewStatus = ProdNewStatus::Completed THEN BEGIN
        IF ProdOrderHead."Remaining Qty." <> 0 THEN BEGIN
          ProdPost.PostProduction(ProdOrderHead2);
        END;
      END;

      //Reload record
      ProdOrderHead2.RESET;
      ProdOrderHead2.GET(ProdOrderNo);

      //Update status        
      ProdOrderStatus.
      ChangeStatusArchived(ProdOrderHead2,ProdNewStatus);
    END;

    ProdOrderNo := '';
    ProdOrderHead2.RESET;

  UNTIL ProdOrderHead.NEXT = 0;

END ELSE BEGIN
  ERROR(Text50013);
END; 

I tried it with several commits because it seems that the transaction in the first loop was not yet closed. If I do the same manually (the same Codeunits) it works.

Has anybody any ideas how to solve that?

Best regards
Felix

Comments

  • krikikriki Member, Moderator Posts: 9,110
    You don't need the COMMIT. That is not the problem, but could create other problems.

    Try this:
    //Post production if new status = Completed
          IF ProdNewStatus = ProdNewStatus::Completed THEN BEGIN
            IF ProdOrderHead."Remaining Qty." <> 0 THEN BEGIN
              CLEAR(ProdPost); // I added this line
              ProdPost.PostProduction(ProdOrderHead2);
            END;
          END;
    
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


Sign In or Register to comment.