Modifying CU5407, Prod. Order Status Management to automate

j.marseloj.marselo Member Posts: 102
Folks,

When Finishing production order, the system will halt on a production order line that has consumption posted but zero output. In fact it's clear on what should be done to fix this. User must post at least 1 output for that prod. order line to allow the production order to change status as Finished.

Question 1: There are no other option open! Is there anyone not agree with this? If there is, please inform what is the other option.

With assumption to post the output is the only option, I think it is efficient to automate the creation of production output. I modify the codeunit to make an output journal when system find a prod. order line that has consumption but no output. I made a change in CU5407, Prod. Order Status Management, in ErrorIfUnableToClearWIP() trigger.

Question 2: What is my risk if I modify the code unit? Instead of the form or create a new report (perhaps) to run the check.

And this is the codes. Since this is a test, the codes is much simplified without parameter, like journal template and batch name, posting date, defective location, qty. to post as output, and etc. (if any).
ErrorIfUnableToClearWIP(ProdOrder : Record "Production Order")
ProdOrderLine.SETRANGE(Status,ProdOrder.Status);
ProdOrderLine.SETRANGE("Prod. Order No.",ProdOrder."No.");
IF ProdOrderLine.FIND('-') THEN
  REPEAT
    IF NOT OutputExists(ProdOrderLine) THEN
      IF MatrOrCapConsumpExists(ProdOrderLine) THEN BEGIN

        //ERROR(Text009,ProdOrderLine."Line No.",ToProdOrder.TABLECAPTION,ProdOrderLine."Prod. Order No.");
        // change above error(... , to message(... , as line below
        MESSAGE(Text009,ProdOrderLine."Line No.",ToProdOrder.TABLECAPTION,ProdOrderLine."Prod. Order No.");

        //jm.2010 0302 : . . . . . . . . . . s t a r t . . . . . . . . . .

        IF NOT DIALOG.CONFIRM('Create required output journal by system?', FALSE) THEN
           ERROR(Text009,ProdOrderLine."Line No.",ToProdOrder.TABLECAPTION,ProdOrderLine."Prod. Order No.");

        itemjnl.SETFILTER("Journal Template Name",'OUTPUT');
        itemjnl.SETFILTER("Journal Batch Name",'DEFAULT');
        IF itemjnl.FIND('+') THEN ln := itemjnl."Line No." ELSE ln := 0;

        itemjnl."Journal Template Name" := 'output';
        itemjnl."Journal Batch Name"    := 'default';
        itemjnl."Line No."              := ln + 10000;
        itemjnl."Posting Date"          := TODAY;
        itemjnl.INSERT; itemjnl.MODIFY;

        itemjnl.VALIDATE("Posting Date");
        itemjnl."Entry Type" := itemjnl."Entry Type"::Output;
        itemjnl.VALIDATE("Entry Type"); itemjnl.MODIFY;
        
        itemjnl."Prod. Order No." := ProdOrderLine."Prod. Order No.";
        itemjnl.VALIDATE("Prod. Order No.");
        itemjnl."Item No." := ProdOrderLine."Item No.";
        itemjnl.VALIDATE("Item No.");
        itemjnl.MODIFY;

        //get operation no.
        prodrtg.SETFILTER(Status,FORMAT(prodrtg.Status::Released));
        prodrtg.SETFILTER("Prod. Order No.",ProdOrderLine."Prod. Order No.");
        prodrtg.SETFILTER("Routing Reference No.", FORMAT(ProdOrderLine."Line No."));
        prodrtg.SETFILTER("Next Operation No.",'');
        prodrtg.FIND('+');

        itemjnl."Operation No." := prodrtg."Operation No.";
        itemjnl.VALIDATE("Operation No.");
        itemjnl.MODIFY;

        //change location code in prod. order line to the defect location.
        ProdOrderLine.GET(ProdOrderLine.Status::Released, ProdOrderLine."Prod. Order No.",ProdOrderLine."Line No.");
        ProdOrderLine."Location Code" := '.DEFECT';
        ProdOrderLine.MODIFY;
        itemjnl."Location Code" := '.DEFECT'; itemjnl.VALIDATE("Location Code"); itemjnl.MODIFY;
        itemjnl."Output Quantity" := 1;       itemjnl.VALIDATE("Output Quantity"); itemjnl.MODIFY;
        COMMIT;

        itemjnl.RESET;
        itemjnl.SETFILTER("Journal Batch Name",'DEFAULT');
        itemjnl.SETFILTER("Location Code",'.DEFECT');
        
        poutf.SETRECORD(itemjnl);
        poutf.RUNMODAL;

        // ##########
        //how to make that form post himself, like pressing F11 key
        { // this can not work, but worth to try. i still don't know how to use sendkey command.
        IF DIALOG.CONFIRM('Post Output Journal rightaway?', FALSE) THEN BEGIN
           CREATE(wsh);
           wsh.SendKeys('{F11}');
           CLEAR(wsh);
        END ELSE
        }
        // ##########
        ERROR(Text009,ProdOrderLine."Line No.",ToProdOrder.TABLECAPTION,ProdOrderLine."Prod. Order No.");

        //jm.2010 0302 : . . . . . . . . . .  e n d  . . . . . . . . . .

        END;
  UNTIL ProdOrderLine.NEXT = 0;

Vars I added:
all Local:
poutf - Form - Output Journal	
itemjnl - Record - Item Journal Line	
prodrtg - Record - Prod. Order Routing Line	
ln - Integer		
wsh - Automation - 'Windows Script Host Object Model'.WshShell

Question 3: Are those lines efficient code? Please suggest me, and I wish to receive inputs.

Question 4: Is there a way to send a command to a form to emulate button press. Like an Output Journal showing up, and from the codeunit there is a command to make the form doing Posting - Post or F11 key. I try to achieve it with codes in near the end, please see at thelines between '##########', but it doesn't works. Anyone can suggest?

I really wish to receive comments and inputs.

Thank you.
Kind regards, Joe Marselo | see my NAV blog joemarselo.wordpress.com | twitter @joemarselo

Comments

  • rajatkaliarajatkalia Member Posts: 65
    Hi

    System gives a warning message anyways. and if the user clicks OK then it is actually a user level error.

    also if u want completely block it in case Finished qty is 0 then may be you could give an error message that Finished Qty cannot be 0, instead of auto populating the Output jnl. That may be easier and may work.


    Regards,
    Rajat.
  • j.marseloj.marselo Member Posts: 102
    rajatkalia wrote:
    System gives a warning message anyways. and if the user clicks OK then it is actually a user level error.
    also if u want completely block it in case Finished qty is 0 then may be you could give an error message that Finished Qty cannot be 0, instead of auto populating the Output jnl. That may be easier and may work.
    in fact, my purpose is not only to stop until system shows error. because after the error, user has only 1 option to proceed, which is to make output journal for that prod. order line with consumption but no output.
    Auto populating journal will make the work of user much easier, instead of just an error message.
    Kind regards, Joe Marselo | see my NAV blog joemarselo.wordpress.com | twitter @joemarselo
  • j.marseloj.marselo Member Posts: 102
    i forgot to describe the scenario of my operation practice.
    we do MTO and proceed sales order as project order, creating production order with status released, right from the sales order. one prod order contains many items, and 1 production order for 1 sales order.
    in the floor, the actual condition, it can be 1 prod. order line has excess output (more than expected output qty.), and we record this as is. there is also 1 prod. order line that consume few material, but considering process time, we decide to use excess products that we have to fulfill the line. as for the sales order, all items and qty's are fulfilled, but as for corresponding prod. order, there is one or more prod order line taking up some components but we cancel the production process, because we decide to use from excess product.

    then when the SO is shipped, we change status of released prod order to finished. when executing this task, the prod order line which has consumption but no output, will give an error message. then NAV will stop, until user create required output for prod order line.

    because we dont have actual output, but we must create one as required by NAV logic processing, so we will create output to virtual (defect) location, with qty. = 1 only, just to satisfy NAV's requirement. this is my purpose, instead of letting user create the output by his own, it can be inputting wrong item or wrong location or wrong date, etc.

    so i plan to automate the output journal, as described in my post above. what do you think?
    Kind regards, Joe Marselo | see my NAV blog joemarselo.wordpress.com | twitter @joemarselo
Sign In or Register to comment.