Post sales order invoice in Dynamicso 365 for operation via code

Hello All:

In ax 2012 I successfully changed the status from Delivery to Invoice

public static void main(Args _args)
         SalesFormLetter salesFormLetter;
         SalesTable salesTable;
         salesTable = SalesTable::find('000714');

        if (salesTable && salesTable.SalesStatus == SalesStatus::Delivered)
           salesFormLetter = SalesFormLetter::construct(DocumentStatus::Invoice);
           salesFormLetter.update(salesTable, systemDateGet(), SalesUpdate::All, AccountOrder::None, NoYes::No, NoYes::No,                NoYes::No, NoYes::Yes);
             info(" Sales Id does not exists or null in the system, please try again!");

The above code snippet works fine in Ax 2012 but doesn't work well in dynamics 365 for operations

Please help as quickly as you can


Shankar :)

  • Hi Shankar,
    Can you perhaps , elaborate what part of the invoice posting does not work well? If you face an error can you describe that error here?Its not clear ,what your precise problem is..
  • In reply to Amit Gupta:

    Hey Amit,
    I want to invoice any Sales order with open order status.. the above code snippet works well in ax 2012.
    I am able to see the sales order status change from open to invoiced in ax 2012
    but it is not working the same in Dynamics 365

    Do you need any other details, please let me know
    Shankar :)
  • Shankar - so now you know that this same code works without any problem. you need to make sure that sales order's SalesStatus should be SalesStatus::BackOrder (for Open Order).
    And then next line should be:
    SalesFormLetter::construct(DocumentStatus::Invoice,null, null, SysOperationExecutionMode::Asynchronous);
    And still if your code doesn't work, then you need to debug the error and post full details here so that it is easy for others to provide right solution.