web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Cannot run form on non interactive session

(0) ShareShare
ReportReport
Posted on by

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?

*This post is locked for comments

I have the same question (0)
  • Brandon Wiese Profile Picture
    17,790 on at

    There are good examples elsewhere in the code for how to print (or render to file) a document without using a menu item.  Try EPSendDocument::makeDocument(..).  It does not specifically have a case for VendInvoiceJour, but it might be quickly adapted to it.  That class exists in 2012, so if it's gone in 365 I'm sure I can post some custom code.

    Regardless, you've already discovered that it's a terrible idea to launch a menu item on a non-UI thread, and potentially on a server thread, and probably sometimes in Batch.  You should find a more appropriate place to attach your code than VendVoucher.

    Also, I'm curious about the throw.  If you already have a VendInvoiceJour records, then it's not proforma, it's an actual invoice.  Did you throw to prevent the Proforma = NoYes::Yes from deleting the VendInvoiceJour record?  If so, you should not be changing the Proforma field of a posted VendInvoiceJour record, let alone sending that unsaved record to other parts of the system.

    You've built something that really only works by luck (and doesn't work in newer and more strict versions of AX) and comes with huge risks because of how you have implemented it.

  • Community Member Profile Picture
    on at

    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?

  • Brandon Wiese Profile Picture
    17,790 on at

    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
    on at

    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.

  • Community Member Profile Picture
    on at

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

  • martinarul Profile Picture
    231 on at

    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?

  • tyhj Profile Picture
    629 on at

    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 ?

  • nec_ronaldy Profile Picture
    10 on at

    Is this issue solved?

    Please help to solve.

  • Martin Dráb Profile Picture
    240,077 Most Valuable Professional on at

    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.

  • Community Member Profile Picture
    on at

    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
    }

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the June Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans