I'm working on an extension to add lines to our item reclass journals. I am using the default /Item Reclass. Journal/ page to add the items and run a codeunit to call /Item Jnl.-Post Batch/ separately to post the batch. This all works as long as my user stays on the same batch. If I post items through the API to the current journal, all goes well. If I post to a journal that is not currently selected, then I get the error:
The Item Journal Batch does not exist. Identification fields and values: Journal Template Name='TRANSFER',Name=''
I have tried setting a filter on the Item Journal Line to the new batch and have run a codeunit to run ItemJnlManagement with an Item Journal Batch record set to the correct batch. Nothing seems to set the environment like opening the page, then running the API.
Here is the code I've tried to run immediately before posting the new record to the page:
procedure PostReclass(batchName: text; postItems: Boolean): Text var lrRec: Record /Item Journal Batch/; begin lrRec.Init(); lrrec.SetFilter(Name, batchName); //lrRec.SetFilter(/Journal Batch Name/, batchName); Codeunit.Run(codeunit::ItemJnlManagement, lrRec); if lrRec.FindFirst() and postItems = true then begin //repeat CODEUNIT.RUN(CODEUNIT::/Item Jnl.-Post Batch/, lrRec); //until rec.next = 0 end; exit(lrRec.Name); end;
then call
the Journal_Batch_Name I'm passing in Json matches the batchName passed above and is a valid batch; yet it complains that there is no valid batch. Any help would be greatly appreciated!