How to post a transfer order using code

jorgitojorgito Member Posts: 115
Hi all.

I have the following situation.

When the customer posts a Purchase Receipt, he need to create and post a Transfer Order for each line of the Receipt.
I tried inserting the following code in C90 for each line.
CODEUNIT.RUN(CODEUNIT::"TransferOrder-Post Shipment", TransferHeader);
CODEUNIT.RUN(CODEUNIT::"TransferOrder-Post Receipt", TransferHeader);

I also tried the following:
TransferPostShipment.RUN(TransferHeader);
TransferPostReceipt.RUN(TransferHeader);

However, if there is an error while posting the Transfer Order, I get an error message but the Purchase Receipt gets posted.

I tried using the return value of the CODEUNIT.RUN, but I get a message saying that write transactions are not allowed.

How can I call the Transfer Post, so that if an error occurs, the whole procedure gets rolled back?

Thanx
Jorgito

Answers

  • krikikriki Member, Moderator Posts: 9,118
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • jorgitojorgito Member Posts: 115
    kriki,

    Thanx for the solution.

    It seems that Navision does not let you run a codeunit that performs a commit, while you are inside a transaction.

    The way to solve this problem is:

    In C5704 (TransferOrder-Post Shipment) and C5705 (TransferOrder-Post Receipt):

    - Create a Boolean variable :
    blnDontUseCommit
    
    - Create a function
    DontUseCommit()
    blnDontUseCommit := TRUE;
    

    - Change all COMMITs to
      IF NOT blnDontUseCommit THEN
        COMMIT;
    

    and finaly you can run the codeunit using
        CLEAR(TransferPostShipment);
        TransferPostShipment.DontUseCommit();
        TransferPostShipment.RUN(TransferHeader);
    

    Jorge
  • krikikriki Member, Moderator Posts: 9,118
    jorgito wrote:
    It seems that Navision does not let you run a codeunit that performs a commit, while you are inside a transaction.
    What do you mean with this?
    You can run a codeunit with a commit while already inside a transaction. The problem is that with the commit in the codeunit, the transaction is commited.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


Sign In or Register to comment.