Showing posts with label AX Techno-Functional. Show all posts
Showing posts with label AX Techno-Functional. Show all posts

Tuesday, September 06, 2011

AX 2009 : Create and Post Inventory Journal


Following is job which will create and post the Inventory Journal in ax 2009 :-

static void createMovJournal(Args _args)
{ InventJournalTable journalTable;
InventJournalTrans journalTrans;
InventJournalTableData journalTableData;
InventJournalTransData journalTransData;
InventTable inventTable;
InventDim inventDim;
Counter cnt;
InventJournalCheckPost journalCheckPost = new InventJournalCheckPost();
DialogButton dbtn;
;

journalTableData = JournalTableData::newTable(journalTable);
journalTransData = journalTableData.journalStatic().newJournalTransData(journalTrans,journalTableData);

// Init JournalTable

journalTable.clear();

journalTable.JournalId = journalTableData.nextJournalId();
journalTable.JournalType = InventJournalType::Movement;
journalTable.JournalNameId = journalTableData.journalStatic().standardJournalNameId(journalTable.JournalType);

journalTableData.initFromJournalName(journalTableData.journalStatic().findJournalName(journalTable.JournalNameId));

// Init JournalTrans
select firstonly inventTable;
for(cnt=1;cnt<10;cnt++)
{
journalTrans.clear();
journalTransData.initFromJournalTable();

journalTrans.TransDate = systemdateget() + 1 div 2;
journalTrans.ItemId ='1103';    //inventTable.ItemId;
journalTrans.Qty = 100;
journalTrans.CostAmount = 100;
journalTrans.LedgerAccountIdOffset='110170';

// Dimension details

inventDim.InventLocationId = '11';
journalTrans.InventDimId ='00000061_069'; //InventDim::findOrCreate(inventDim).inventDimId;

journalTransData.create();



}

journalTable.insert();

// Call the static method to post the journal
if(InventJournalCheckPost::newPostJournal(journalTable).validate())

if(box::yesNo("Do you want to Post Now?",DialogButton::No)==DialogButton::Yes)
{
InventJournalCheckPost::newPostJournal(journalTable).run();
}
else
{
 box::info("Not Posted");
}
info("done");

}


Enjoy DAX.
Cheers !!@

Posting SalesOrder Confirmation with SalesFormLetter Class in Ax 2009

The Book of orders in Microsoft Dynamics AX is done through the class "sales form letter" or one of its more concrete (derived) classes.
Each reservation type (eg confirmation, delivery note, invoice) is represented by a class that is derived from the base class "sales form letter" (see illustration).
To reserve an order by code, an object of class "sales form letter" can be created.
salesFormLetter = SalesFormLetter::construct(DocumentStatus::Confirmation);
This is done as common practice in Microsoft Dynamics AX, on the "construct" method of the class. must be specified as parameters to this method the desired type of booking (eg confirmation, delivery note, invoice).
The "construct" a method generates the appropriate transaction type, object and returns that (in this case, a "SalesFormLetter_Confirm" object created).
The actual book is called the method "update". Since this method can all be submitted for the booking necessary data as parameters, is a single assignment of such a mandate which is to be posted not necessary.
For example:
// — — Book without print 
static void PostingConfimation(Args _args) 

SalesFormLetter salesFormLetter; 
SalesTable salesTable; 
SalesId salesId; 
PrintJobSettings printJobSettings; 

//Angabe des Auftrags, welcher gebucht werden soll. 
salesId = "00423_036"; 
salesTable = SalesTable::find(salesId); 
// Bestimmen des Buchungstyps durch Angabe des DocumentStatus 
salesFormLetter = SalesFormLetter::construct(DocumentStatus::Confirmation); 
//Buchen des Auftrags (aber nicht Drucken). 
salesFormLetter.update(salesTable, 
SystemDateGet(), 
SalesUpdate::All, 
AccountOrder::None, 
NoYes::No, 
NoYes::No); 
}

This example is good to see that necessary for the posting of a job essentially only two steps.
  1. On the method "construct" the company produce a type PCX object.
  2. By calling the method "update" to book the order.
Of course, even more extensive or more specialized booking scenarios with the class are ready to buy "sales form letter." For example it is possible to print the same booking with these documents (once, several times and in different formats), open to the mask for the booking (for the user to influence within the company) or the booking is not directly run, but this provide for batch processing.
Thus, it is not too complex, just one more example of booking and simultaneously print the appropriate documents.
// — — Book with print 
static void PostingConfimation(Args _args) 

SalesFormLetter salesFormLetter; 
SalesTable salesTable; 
SalesId salesId; 
PrintJobSettings printJobSettings; 

salesId = "00423_036"; 
salesTable = SalesTable::find(salesId); 
salesFormLetter = SalesFormLetter::construct(DocumentStatus::Confirmation); 
salesFormLetter.update(salesTable, 
SystemDateGet(), 
SalesUpdate::All, 
AccountOrder::None, 
NoYes::No, 
NoYes::Yes); 
printJobSettings = new PrintJobSettings(salesFormLetter.printerSettingsFormletter( 
PrintSetupOriginalCopy::Original)); 
printJobSettings.setTarget(PrintMedium::File); 
printJobSettings.format(PrintFormat::PDF); 
printJobSettings.fileName(@"C:\Test_Order.pdf"); 
salesFormLetter.updatePrinterSettingsFormLetter(printJobSettings.packPrintJobSettings()); 
salesFormLetter.printJournal(); 
}
http://blogs.bojensen.eu/?p=330
Source:

Post a Ledger Journal in AX 2009 using X++


Following is the code for Posting a Ledger Journal using X++ :


static void ExampleLedgerJournal(Args _args)
{
LedgerJournalName LedgerJournalName;
LedgerJournalTable ledgerJournalTable;
LedgerJournalTrans ledgerJournalTrans;
LedgerJournalCheckPost ledgerJournalCheckPost;
NumberSeq numberseq;
LedgerJournalNameId LedgerJournalNameId = 'GenJrn';
BankAccountID BankAccountID = 'EUR OPER';
ledgerAccount offsetAccount = '601500';
amountCur amountCur = 102;
;
ttsbegin;
// Find a ledgerJournalName record
select firstonly LedgerJournalName
where LedgerJournalName.JournalName ==LedgerJournalNameId;
//Created the ledgerJournalTable
ledgerJournalTable.JournalName =LedgerJournalName.JournalName;
ledgerJournalTable.initFromLedgerJournalName();
ledgerJournalTable.Name = 'Hotel';
ledgerJournalTable.insert();
numberseq =NumberSeq::newGetVoucherFromCode(ledgerJournalName.VoucherSeries);
ledgerJournalTrans.Voucher = numberseq.voucher();
//Generate the transaction line
ledgerJournalTrans.JournalNum =ledgerJournalTable.JournalNum;
ledgerJournalTrans.CurrencyCode = 'EUR';
ledgerJournalTrans.ExchRate =Currency::exchRate(ledgerJournalTrans.CurrencyCode);
ledgerJournalTrans.AccountNum = BankAccountID;
ledgerJournalTrans.AccountType =LedgerJournalACType::Bank;
ledgerJournalTrans.AmountCurCredit = amountCur;
//Pass the Date . You can also use str2Date('08/08/2008') if period is not defined.
ledgerJournalTrans.TransDate = today();
ledgerJournalTrans.Txt = 'Room Stay';
ledgerJournalTrans.OffsetAccount = offsetAccount;
ledgerJournalTrans.OffsetAccountType =LedgerJournalACType::Ledger;
ledgerJournalTrans.insert();
info(strfmt('Journal Id:%1',ledgerJournalTable.JournalNum));
//Post the Journal
ledgerJournalCheckPost= ledgerJournalCheckPost::newLedgerJournalTable(ledgerJournalTable,NoYes::Yes));
ledgerJournalCheckPost.run();
ttscommit;
}

Delete caches in Dynamics 365 F&O

In Dynamics 365 Finance and Operations (D365 F&O), clearing the Application Object Tree (AOT) cache usually involves running specific ut...