Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX forum
Unanswered

Cannot run form on non interactive session

Posted on by Microsoft Employee

Hi all,

i'm tring to run a report during the posting of a ledger journal table to print a proforma invoice for a vendor. In AX 2012 it worked by customizing the post VendVoucher.post() method calling the the report by menuFunction. So in 365 i have extened the VendVoucher this way:

[ExtensionOf(ClassStr(VendVoucher))]
final class PAC001aVendVoucher_Extension
{
    public void post(LedgerVoucher   _ledgerPostingJournal,
                     CustVendTrans   _vendTrans,
                     NoYes           _approval,
                     UnknownNoYes    _euroTriangulation,
                     boolean         _withHoldTaxType,
                     boolean         _useSubLedger)
    {

        ledgerJournalTable  ledgerJournalTable;
        ledgerJournalTrans  ledgerJournalTrans;
        ;

        ttsbegin;

        next post(_ledgerPostingJournal, _vendTrans, _approval, _euroTriangulation, _withHoldTaxType, _useSubLedger);
 
        if (common.TableId == tablenum(LedgerJournalTrans))
        {
            LedgerJournalTrans = common;
            ledgerJournalTable = LedgerJournalTrans.ledgerJournalTable();
        }

        if(ledgerJournalTable.PAC001aPrintProforma)
            this.PAC001aCommissionPrintJournal(vendInvoiceJour);
 
        ttscommit;
    }

    void PAC001aCommissionPrintJournal(vendInvoiceJour _vendInvoiceJour)
    {

        Args args;

        ;
        _vendInvoiceJour.Proforma   = NoYes::Yes;
        args = new Args();
        args.name(identifierStr(PurchInvoiceOriginal));
        args.record(_vendInvoiceJour);
        new menuFunction('PAC001aAgentProformaInvoice', MenuItemType::Output).run(args);
        //new menuFunction('PurchInvoiceOriginal', MenuItemType::Output).run(args);

        throw error(strFmt("%1 %2", "@SYS119253",_vendInvoiceJour.vendName()));

    }

}

where the throw error is needed beacuse i want to rollback the process after the report has printed to screen.

In Ax 365 this gives me the error :

"Stack trace: Cannot run form on non interactive session"

Someone can halp me to print the report and rollback as i can do in ax 2012?

  • Ludovico M. Profile Picture
    Ludovico M. 5 on at
    Cannot run form on non interactive session
    I got the same problem. I have to print a report while posting a product receipt, but everything I tried doesn't work. Anyone got a solution?
  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Cannot run form on non interactive session

    Got this problem today after cleaning up BP violations. 

    For me the culprit was this method in a class that extended RunBaseBatch.

    public boolean canRunInNewSession()
    {
    return true; //change to false and error is gone
    }

  • Martin Dráb Profile Picture
    Martin Dráb 225,526 Super User on at
    RE: Cannot run form on non interactive session

    You can't run a dialog in a non-interactive session. As there is no user, nobody can fill values and confirm the dialog. Therefore if it was somehow possible, it would be last thing that the process would do.

  • nec_ronaldy Profile Picture
    nec_ronaldy 10 on at
    RE: Cannot run form on non interactive session

    Is this issue solved?

    Please help to solve.

  • tyhj Profile Picture
    tyhj 625 on at
    RE: Cannot run form on non interactive session

    I have a custom report to print after product receipt is posted OK, there is a parameter to enable printing, if I printed together with the product receipt, it is printed OK. But if I want to print my custom report alone, then there is error : "Stack trace: Cannot run form on non interactive session"

    When debug, dialogForm.formRun().run(); is giving the error.

    print custom report only: formRun is SysOperationTemplateForm

    print product receipt then custom report: formRun is SrsReportViewerForm

    How can i change my report call to use the correct formRun ?

  • martinarul Profile Picture
    martinarul 215 on at
    RE: Cannot run form on non interactive session

    Hi Nyonik

      Did you resolve the issue,  I am facing the same problem while opening a report in D365.

    Can you please tell me the solution?

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Cannot run form on non interactive session

    As suggested i moved the method from VendVoucher to LedgerJournalTransUpdateVend but i have the same error.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Cannot run form on non interactive session

    I'm sorry but you miss the point: that method is only called when needed and in 6 years of implementation we had 0 problems about that in 3 different version of AX 2009, 2012 2012 R3 in many customer using it. Are you suggesting me that VendVoucher is executed in non interactive session while LedgerJournalCheck post will run in interactive session? If it is so, how can i check it?  So, what i'm asking is how can i check and control in AX 365 if the session is interactive or non interactive.

  • Brandon Wiese Profile Picture
    Brandon Wiese 17,786 on at
    RE: Cannot run form on non interactive session

    I'm sure once you got it working it kept working for you, that's not what I meant by risk.

    What I meant by risk is a departure from best practices or from sound development practices, such that modifications can be broken by hotfixes, patches, upgrades, other developers, or even just circumstances outside your control.  I've seen AX code that broke from Windows Updates related to Internet Explorer.

    In your specific case, you should not launch an interactive menu item from VendVoucher.  That code runs deep inside of many other processes, and you have no control over where or how.  It will run in Batch.  It will run on the server (on AX 2012 anyway).  It will check permissions at a place where they should no longer matter.

    Regardless of my opinion about your implementation, the fact remains that it will not work any longer.  Perhaps you should consider printing your documents in the class responsible for journal posting instead.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Cannot run form on non interactive session

    There is no risk with the code. It works without any problems since 6 year in both ax 2009 and ax 2012. The problem here it is not the throw error command used for roll back. The problem is that in ax 365 it don't print the report as it did without problem in 2009 e 2012. I already tried moving the print outside the vend voucher but nothing as changed.

    How can I control if a session is interactive or non interactive?

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 287,835 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,526 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans