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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Create vendor invoice by code, using FormRun object

(0) ShareShare
ReportReport
Posted on by

Hi everybody,

I would like to know if it is possible to create a new blank vendor invoice using Formrun object instead of MenuFunction object. The reason is that I need to detach the child form from the parent, which I cannot do with a MenuFunction object.

Thank you for your time,

MozaikAX.

*This post is locked for comments

I have the same question (0)
  • Martin Dráb Profile Picture
    239,040 Most Valuable Professional on at

    What do you mean by creating a blank invoice?

    In general, if you have a menu item (MenuFunction) pointing to a form, you can instantiate the form directly. But it's not clear which menu item you're talking about and whether it will help to "create a new blank vendor invoice".

  • Community Member Profile Picture
    on at

    Let's say I activate the vendor invoice workflow and I open a new vendor invoice, I complete it and then I submit it. After submitting the invoice, I would like to automatically close the invoice and pop a new one, which I could complete, submit and another invoice would open, and so on... So far, I have been able to close the invoice after submitting and I have tried to use the MenuFunction to open a new invoice, but it seems that I can't open it because it is not "detached" from the parent (the first vendor invoice which I just submitted)

    So I have tried this code :

    MenuFunction menuFunction;

    menuFunction = new MenuFunction(menuitemActionStr(PurchFormLetter_NewInvoiceAction), MenuItemType::Action);

    menuFunction.run();

    When I use it in a job, it works just fine, but when I use it after closing the first invoice, it never opens, and the first invoice does not close. I have placed this code in Class\VendInvoiceHeaderWorkflow\main at the end of the method like this :

    if (  _args.caller().name() == formStr(VendEditInvoice))

      {

          _args.caller().close();

          menuFunction = new MenuFunction(menuitemActionStr     (PurchFormLetter_NewInvoiceAction), MenuItemType::Action);

          menuFunction.run();

      }

    And this is why I was wondering if it would be better to use the FormRun class to open the new invoice instead of the MenuFunction. I have been working on this code :

    PurchFormLetter purch;

    Args args;

    FormRun run;

       purch = PurchFormLetter::construct(DocumentStatus::Invoice, classStr(FormletterService), methodStr(FormletterService, postPurchaseOrderInvoice), SysOperationExecutionMode::Synchronous, menuitemActionStr("VendEditInvoice"));

       args = new args(formStr(VendEditInvoice));

       args.caller(purch);

       run = ClassFactory.formRunClass(args);

       run.init();

       run.run();

       run.detach();

  • Martin Dráb Profile Picture
    239,040 Most Valuable Professional on at

    Can you tell me what you're doing from user perspective (where you go in menu etc.)?

  • Community Member Profile Picture
    on at

    I go in accounts payable, then in the open vendor invoices listpage. In the upper menu, I click on "Invoice" and finally "vendor invoice". In the invoice, I complete the header section and the lines. When I'm done, I click on submit (assuming the vendor invoice workflow is activated).

    This is where I would like to close the invoice after the submitting process is done and open a new one.

  • Verified answer
    Martin Dráb Profile Picture
    239,040 Most Valuable Professional on at

    Thanks, I think I understand it now.

    The VendEditInvoice form is called as a SysOperation dialog and I don't think you can reasonably close such a dialog and open another dialog at its place. You should first get out of SysOperationServerController.prompt() and only then you can start another operation. Therefore you have to change your design; the current one doesn't respect the actual situation.

    The easiest solution may be injecting a custom class between the "Vendor invoice" button and PurchFormLetter class and putting your logic there, e.g. potentially calling PurchFormLetter several times.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Joris dG Profile Picture

Joris dG 5

#2
Alexey Lekanov Profile Picture

Alexey Lekanov 2

#2
Henrik Nordlöf Profile Picture

Henrik Nordlöf 2 User Group Leader

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans