Sunday, November 16, 2008

Financial posting in dynamics ax

Question: How to use the exisitng posting to ledger API. Is there any documentation available.

Answer: The API documentation can be found at http://download.microsoft.com/download/d/b/a/dba4455a-25c1-495c-bad2-3b316e0e2434/PostToLedger.pdf . Also I have written a blog entry for this you can check that out as well.

Friday, November 14, 2008

Inside Dynamics AX 4.0 Free eBook download at microsoft

The best technical resource available for Dynamics AX 4.0 programming is available for free download. Please download it from here . It is a must read.

How to catch key stokes in Dynamics AX

Question: I want to catch key strokes from the dynamcis ax form. How can I do it?
Answer: Override the task() method of the form and add a case in the switch method to check the keystroke. The task macro is available in the macro library that can be used to catch different events.

Friday, November 7, 2008

LIKE statement in Dynamcis AX

Question: How can we use like statement in Dynamics AX.
Answer: We can use 'like' clause in Dynamics AX statement by using '*' in the wild cards.
static void likeStatement(Args _args)
{
CustTable custTable;
;
while select custTable where custTable.Name like '*The*'
{
print custTable.Name;
}
pause;
}

In order to use linke statement in query use the '*' wild card in the query ranges. Something like the following,
static void likeQuery()
{
Query query = new Query();
QueryRun queryRun;
;
query.addDataSource(tableNum(CustTable)).addRange(fieldNum(CustTable, AccountNum)).value('400*');
queryRun = new QueryRun(query);
if(queryRun.next()) {
purchTable = queryRun.get(tableNum(CustTable));
print custTable.AccountNum;
pause;
}

Tuesday, August 5, 2008

Dynamics AX Development Training Plan

Below is a training plan i normally use to train new developers in my firm.
Task No Task Description
1.Installing AX, AX 4.0 Development Mock 1
2.Morphx IT, Chapter 3 – Data Dictionary
3. Inside Dynamics AX , Chapter 12 – The Database Layer
4.Morphx IT, Chapter 5 – Classes
5.Inside Dynamics AX, Chapter 5 – The X++ programming language
6.Morphx IT, Chapter 6 – Forms
7.Morphx IT, Chapter 7 – Reports
8.Inside Dynamics AX, Chapter 6 – Customizing Microsoft Dynamics AX
9.Inside Dynamics AX, Chapter 7 – Extending Microsoft Dynamics AX

Tuesday, April 29, 2008

Hide an element from the combo box

Question
I have an enum with values Element1, Element2 and Element3. Now this enum is being used on two different locations what the requirement is that i have to add another element Element4 in to the enum but this should only reflect on one location.

Answer
Let say you you two forms where this enum is reflected, namely Form1 and Form2. In order to hide an element from Form1 and continue showing it on Form2 go to form design and then access that combo box control. Override the enter() method of that combo box and write this line to delete the element from it.

combobox:enter()
{
super();
this.delete(enum2str(BaseEnum::Element4));
}

Friday, April 11, 2008

Change Type of a Control on the Runtime

Question: How can we chnage the type on same control on the run time. I have a scenario where the same control is bind to EDT at one point and ENUm at other. How to solve this problem.
Answer: Coming Soon!

Friday, April 4, 2008

Posting in the General Ledger (GL)


Question:
How to create a posting entry in General Ledger (GL) module of Dynamics AX?

Answer:
There are many ways to create posting entries in to General Ledger module. In my experience the simplest way is to use the Journal classes. There are two parts of posting create a heade entry and then create the add lines to it. To create a header entry use the LedgerJournalTable table and use the LedgerJournalTrans table. Finally use the ledgerJournalCheckPost class object to post these entries into the system.
Below is a job explaing the Posting process in a simple way.
static void postVoucherThroughJournal(Args _args)
{
Dialog dialog = new Dialog("Ledger Posting Example");
DialogField ledgerAccountField;
DialogField offsetAccountField;
DialogField ledgerJournalDescription;
DialogField ledgerAmount;
DialogField ledgerTransDescription;

LedgerJournalTable ledgerJournalTable;
LedgerJournalTrans ledgerJournalTrans;
LedgerJournalCheckPost ledgerJournalCheckPost;
NumberSeq numberSeq;
;
dialog.addGroup("Post Ledger Voucher");
//Add Fields
ledgerAccountField = dialog.addField(typeid(LedgerAccount), "Ledger Account");
offsetAccountField = dialog.addField(typeid(LedgerAccount), "Offset Account");
ledgerJournalDescription = dialog.addField(typeid(Name), "Journal Name");
ledgerAmount = dialog.addField(typeid(AmountCurDebit), "Debit Amount");
ledgerTransDescription = dialog.addField(typeid(Name), "Transaction Text");

if(dialog.run())
{
ttsbegin;
//STEP1: INSERT Journal Header
ledgerJournalTable.JournalName = 'Day1'; /This is the journal name.
ledgerJournalTable.initFromLedgerJournalName();
ledgerJournalTable.Name = ledgerJournalDescription.value();
ledgerJournalTable.JournalNum = JournalTableData::newTable(ledgerJournalTable).nextJournalId();
ledgerJournalTable.insert();

//STEP2: INSERT Journal Details
numberSeq = NumberSeq::newGetVoucherFromCode(LedgerJournalName::find(ledgerJournalTable.JournalName).VoucherSeries);
ledgerJournalTrans.Voucher = numberSeq.voucher();
ledgerJournalTrans.JournalNum = ledgerJournalTable.JournalNum;
ledgerJournalTrans.CurrencyCode = CompanyInfo::standardCurrency();
ledgerJournalTrans.ExchRate = Currency::exchRate(ledgerJournalTrans.CurrencyCode);
ledgerJournalTrans.AccountNum = ledgerAccountField.value();
ledgerJournalTrans.AmountCurDebit = ledgerAmount.value();
ledgerJournalTrans.TransDate = Today();
ledgerJournalTrans.OffsetAccount = offsetAccountField.value();
ledgerJournalTrans.Txt = ledgerTransDescription.value();
ledgerJournalTrans.insert();
//Post Journal into Ledger Accounts
ledgerJournalCheckPost = LedgerJournalCheckPost::newLedgerJournalTable(ledgerJournalTable, NoYes::Yes);
ledgerJournalCheckPost.run();
ttscommit;
Info(StrFmt("Journal %1 is posted", ledgerJournalTable.JournalNum));
}
}

Monday, March 24, 2008

Create Custom Lookups Dynamics AX

Question:
How can we create customized lookups in Dynamics AX
Answer:
One way of creating a custom lookup is by using the power of SysQuery. Lets solve this using a scenario, we want to create a customized vendor lookup that will be used on the Item form. We will define a vendor type and an item type and the vendor that matches the item type on the purchase order form shall be displayed in the lookup. So in order to get this output we will create a method lookupVendor() in the Vendor table and we will call this method from the overridden lookup() method of the Vendor.VendorId field of Vendor datasource passing in the item type from the form.
New method created in the Vendor table
public client static void lookupVendor(FormStringControl _ctrl,
VehicleVendorType _vehicleVendorType)
{

SysTableLookup sysTableLookup = SysTableLookup::newParameters(tablenum(VehicleVendor), _ctrl);
Query query = new Query();
QueryBuildDataSource qbds;
QueryBuildRange vehicleVendorFuelFilter;
;
sysTableLookup.addLookupfield(fieldnum(VehicleVendor, VendorId), true);
sysTableLookup.addLookupfield(fieldnum(VehicleVendor, VendorName));
qbds = query.addDataSource(tablenum(VehicleVendor));
switch (_vehicleVendorType)
{
case VehicleVendorType::Fuel:
qbds.addRange(fieldnum(VehicleVendor, IsFuelVendor)).value(queryValue(NoYes::Yes));
break;
case VehicleVendorType::Mantienance:
qbds.addRange(fieldnum(VehicleVendor, IsMantenanceVendor)).value(queryValue(NoYes::Yes));
break;
case VehicleVendorType::Manufacturer:
qbds.addRange(fieldnum(VehicleVendor, IsFuelVendor)).value(queryValue(NoYes::Yes));
break;
case VehicleVendorType::Tyre:
qbds.addRange(fieldnum(VehicleVendor, IsManufacturer)).value(queryValue(NoYes::Yes));
break;
case VehicleVendorType::Vehicle:
qbds.addRange(fieldnum(VehicleVendor, IsVehicleVendor)).value(queryValue(NoYes::Yes));
break;
}
sysTableLookup.parmQuery(query);
sysTableLookup.performFormLookup();
}

Overridden method of Vendor.VendorId on Vendor Datasource

public void lookup(FormControl _formControl, str _filterStr)
{
;
VehicleVendor::lookupVendor(_formControl, VehicleVendorType::Fuel);
}