The following C/AL functions can be used only to a limited d

tompynationtompynation Member Posts: 398
This code is being executed when a user clicks a button:
btnFase3 - OnPush()
ItemJnlBatch.GET('ARTIKEL','O. GEWICHT');
lv_DocNo := NoSeriesMgt.TryGetNextNo(ItemJnlBatch."No. Series",WORKDATE);

lv_ItemJnlLine.RESET;
lv_ItemJnlLine.INIT;
lv_ItemJnlLine."Journal Template Name" := 'ARTIKEL';
lv_ItemJnlLine."Journal Batch Name" := 'O. GEWICHT';
lv_ItemJnlLine."Posting Date" := WORKDATE;
lv_ItemJnlLine."Line No."  := lv_ItemJnlLine.GetNextLineNo('ARTIKEL','O. GEWICHT');;
// lv_ItemJnlLine."Item No." := lv_ProdOrder."Source No.";
lv_ItemJnlLine."Item No." := 'GRIND 1-3';
lv_ItemJnlLine."Document No." := lv_DocNo;
lv_ItemJnlLine."Entry Type" := lv_ItemJnlLine."Entry Type"::"Positive Adjmt.";
lv_ItemJnlLine.Quantity := Overgewicht;
lv_ItemJnlLine.INSERT(TRUE);
COMMIT;
CODEUNIT.RUN(CODEUNIT::"Item Jnl.-Post",lv_ItemJnlLine);

But this is giving me the error:

The following C/AL functions can be used only to a limited degree during write transactions (because one or more tables will be locked).

Form.RunModal() is not allowed in write transactions.

CodeUnit.RUN is allowed in write transactions only if the return value is not used. For example, 'OK := CodeUnit.Run()' is not allowed.

...


How can i solve this ?

Comments

  • garakgarak Member Posts: 3,263
    why do you fill a "real" item yournal line and not, like in CU 80 or 90, a "hidden" Journalk (without inserting the lines in the journal) ?
    Do you make it right, it works too!
  • kinekine Member Posts: 12,562
    1) Do not use constants, use some setup table to set the template and batch
    2) Move the code into some function and call the functionfrom the OnPush, else you will loose the code when somebody delete the button etc.
    3) Enable debugger and look where it will stop, there must be some oint in the no. series selection or somewhere else when the NAV is trying to show you some form, but the transaction already started.
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • garakgarak Member Posts: 3,263
    Also you write datas in a Journal that can be used by a user :!:

    What is, if an user use the Journal 'ARTIKEL' / 'O. GEWICHT' ? U post your lines after create. If also a user insert there lines, these post you also. Is this correct? I think not or?

    Why do you not create the lines and post them like the standard it does`?
    Take a look into CU 80 or 90 in function "PostItemJnlLine()" and use the same way

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