Do you need to automatically post a sales order, payment journal, or inventory journal in Dynamics AX 2009 using X++. Most of the time developers are just unaware of the classes they need to use to facilitate automatic posting. For example, lets say there is custom form that has a subset of sales orders displayed in a grid and there is button on the right that says post Invoice. By clicking this button a sales order will automatically be posted and printed if all validations for posting a invoice are passed.
To post an invoice using a simple button click you could just add the menu item of type SalesFormLetter but in this case you would like to bypass the posting form that appears when using the standard posting class/main method. On a method on the table or form you could use a method to be called by the button under the clicked method.
SalesFormLetter salesFormLetter;
salesTable findRec;
SalesTable salesTableUpdate;
;
salesTable = salesTable::find(myTable.salesId);
if(salesTable)
{
//The construct method will allow me to pass in the document status I would like to complete which in this case is invoice
salesFormLetter = SalesFormLetter::construct(DocumentStatus::Invoice);
salesFormLetter.transDate(systemdateget());
//You can pass in the date of the posting systemDateGet() retrieves the date the application is set to
salesFormLetter.update(salesTable, // pass in the active salesTable record
systemdateget(), // pass in the date
salesUpdate::All, // Sales update parameter is specifying what quantities you want to invoice in this case we are updating all but we could update Packing slip or picking list etc
AccountOrder::None, //Parameter is based upon if you have any specified order to group sales orders by when posting
false, // Determines if we are posting a proforma or not
true, // Determines if we want to print the report
false, // Determines if we want to use print management to route the document to specified destination
false, // Determines if we are checking the credit remaining for this customer
connull()); // Determines if we are passing in a container containing a list of orders
This function will post and print an invoice without the use of the posting form
}
To post a straight payment journal for example there is a different class you would use . Of course you would need to have your journals created and these can be created using code or you could be using existing journals. So in this example lets say you have the journals and now you want to loop through and post a few. The class ledgerJournalCheckPost will allow you to post an existing payment journal by passing in the header record from the table LedgerJournalTable.
ledgerJournalCheckPost = ledgerJournalCheckPost::newLedgerJournalTable(ledgerJournalTable,NoYes::Yes); ledgerJournalCheckPost.run(true);
To post a transfer journal for inventory transfers the code is very similar to posting a financial journal.
InventJournalCheckPost allows you to post an inventory journal if all validations are passed
journalCheckPost = InventJournalCheckPost::newPostJournal(InventJournalTable::find(inventJournalTable.JournalId)); journalCheckPost.run() ;
When doing automatic posting its important to validate the data and setup before attempting to do mass postings.
This allows the process to complete in a timely manner and allows for accurate postings.

greetings my name is Rick H.
I just discovered this website and already love it.
Nice to be here , see you soon on others forum threads
I love cars , costume italien and old movies
Today is ethical ill, isn’t it?
You are a very clever person!