Friday, October 5, 2012

Changing numerals to text in Indian Format amount in words India

Changing numerals to text in Indian Format

static TempStr numerals2Txt_IN(real _num)

int numOfPennies = (decround(frac(_num), 2) * 100) mod 100;

real test = _num - frac(_num);
int numOfTenths;

str 20 ones[19], tenths[9], hundreds, thousands, lakhs, crores;
int64 temp;

str 200 returntxt;

str 200 pennytxt;

int penny;

real modOperator(real a1, real a2)


int tmpi;

real tmp1, tmp2;

tmp1 = a1 / a2;

tmpi = real2int(tmp1);

tmp2 = tmpi;

return (tmp1 - tmp2)*a2;


real checkPower(real _test, int64 _power)


int64 numOfPower;

if (_test >= _power)


numOfPower = _test div _power;

if (numOfPower >= 100)


temp = numOfPower div 100;

returntxt = returntxt + ' ' + ones[temp] + ' ' + hundreds;

numOfPower = numOfPower mod 100;


if (numOfPower >= 20)


temp = numOfPower div 10;

returntxt = returntxt + ' ' + tenths[temp];

numOfPower = numOfPower mod 10;


if (numOfPower >= 1)


returntxt = returntxt + ' ' + ones[numOfPower];

numOfPower = numOfPower mod 10;




case 10000000 :


returntxt = returntxt + ' ' + Crores;

_test = modOperator(_test, 10000000);



case 100000 :


returntxt = returntxt + ' ' + lakhs;

_test = modOperator(_test, 100000);



case 1000 :


returntxt = returntxt + ' ' + thousands;

_test = modOperator(_test, 1000);



case 100 :


returntxt = returntxt + ' ' + hundreds;

_test = modOperator(_test, 100);





return _test;

































#Define.text_and('Rupees and')

#Define.text_paise('Paise Only')

#Define.text_ruppe('Rupees Only')

ones[1] = #text_1;

ones[2] = #text_2;

ones[3] = #text_3;

ones[4] = #text_4;

ones[5] = #text_5;

ones[6] = #text_6;

ones[7] = #text_7;

ones[8] = #text_8;

ones[9] = #text_9;

ones[10] = #text_10;

ones[11] = #text_11;

ones[12] = #text_12;

ones[13] = #text_13;

ones[14] = #text_14;

ones[15] = #text_15;

ones[16] = #text_16;

ones[17] = #text_17;

ones[18] = #text_18;

ones[19] = #text_19;

tenths[1] = 'Not used';

tenths[2] = #text_20;

tenths[3] = #text_30;

tenths[4] = #text_40;

tenths[5] = #text_50;

tenths[6] = #text_60;

tenths[7] = #text_70;

tenths[8] = #text_80;

tenths[9] = #text_90;

hundreds = #text_100;

thousands = #text_1000;

lakhs = #text_100000;

crores = #text_10000000;

test = checkPower(test, 10000000);

test = checkPower(test, 100000);

test = checkPower(test, 1000);

test = checkPower(test, 100);

if (test >= 20)


numOfTenths = test div 10;

returntxt = returntxt + ' ' + tenths[numofTenths];

numOfTenths = numOfTenths mod 10;

test = test mod 10;


if (test >= 1)


numOfTenths = real2int(test);

returntxt = returntxt + ' ' + ones[numOfTenths];


if (numOfPennies)


if (numOfPennies >= 20)


penny = numOfPennies div 10;

pennytxt = tenths[penny];

numOfPennies = numOfPennies mod 10;


if (numOfPennies >= 1)


pennytxt = pennytxt + ' ' + ones[numOfPennies];


returntxt = returntxt + ' ' + #text_and + ' ' + pennytxt + ' ' +#text_paise;




returntxt = returntxt + ' ' + #text_ruppe;


return returntxt;


Tuesday, September 4, 2012

Get day, month and year from date in axapta x++

Get day, month and year from date in axapta x++
Hi, everybody!
In Dynamics AX, sometimes we need to get the day, month or year from a date and we don't know how to do this... but we can do this easily...

//Get day from date

//Get month from date

//Get year from date

Good DaXing!

Friday, August 31, 2012

Cross-company Support In Ax2012

Cross-company Support
Microsoft Dynamics AX can have multiple companies in one data base. Ex: container conCompanies = [ 'cee', 'ceu' ]; custTable custTable;
while select crossCompany : conCompanies custTable
print custTable.accountNum;

Eventing In Ax2012

Lets the user use a publisher and subscriber model when modifying MDAX2012.
Events can be modeled in the AOT or be used as a programming construct and can be handled in either X++ code or in managed code.
NOTE: Modeled events are only available on classes and not tables or forms.
Eventing Terminology
MDAX2012 events are modeled after the .NET event concepts :
Producer :- The producer is the logic that contains the code that causes a change. This means that it is the entity that emits events.
Consumer :- The consumer is the application code that manifested an interest in being notified when a specific event occurs. This means that it is an entity that receives events.
Event :- An event is a representation of a change that happened in the producer. Microsoft Dynamics AX 6.0 supports Pre and Post events that occur before and after a method is called.
Event Payload :- The event payload is the information that the event carries with it. If a person is hired, for example, the payload includes the employee's name and date of birth, and so on.
Delegate :- A delegate is the definition of the information passed from the producer to the consumer when an event happens.
Event Handlers
Event handlers are methods that are called when the delegate is called, directly through code (for the coded events) or from the environment (in the modeled events). The relationship between the delegate and the handlers can be maintained in code or in the AOT.
Delegate is a keyword.
When program conditions meet the programmer's criteria for the event, the X++ code can call the delegate, and that causes the delegate to call all the event handler methods that are added to the delegate.
To create a delegate, right-click the class and select New->Delegate.
Adding Handlers in the AOT
The user must identify a static method to handle the event on the delegate. However, when adding event handlers from code, described in the following material, instance methods are also applicable as event handlers. Event handlers can be added to the delegate by dragging the event handler to the delegate node that represents the event to be handled.
Adding Handlers in Code
Use special X++ syntax to remove or add event handlers to events. The delegate name appears on the left side of the += operator.
private void AddStaticHandler()
this.MyDelegate += eventhandler
Pre and Post Events
You can subscribe an event handler to automatically run immediately before a method is run.
The event handler can change the parameter values before they are entered into the method. You can also subscribe an event handler to run immediately after a method is run. The event handler can change the value that is returned by the method, before the return value is received by the caller of the method.

Event handlers for these before and after events are visible in the AOT as sub nodes on the methods to which they apply.
Primary Index
A primary key is one or more columns that uniquely identify one record in a table from all the other records. A primary index is a unique index for a table that defines the primary key for that table. To set an index as a unique index, set the index property Allow Duplicates to No.
To set the primary index on a table, open the property sheet for the table. The PrimaryIndex property allows any unique index with a key that is mandatory and cannot be edited.
Surrogate Key
When a primary index is not specified, Microsoft Dynamics AX 2012 uses a Surrogate Key as the primary index. This key is the RecId field and, if the table is saved per company, the DataAreaId. The surrogate key is used on many relations between tables.

Tables Vs Classes In Ax2012

Tables as Classes
A table can be considered an independent class used to address fields or methods defined on that table. In fact when a table is instantiated, it is done so with the system class called xRecord. This class contains methods called when committing record changes to the database and some other system methods that operate on records.
Differences between tables and classes include the following:
• A place for a table buffer is automatically assigned in a table (in classes the new method is used).
• Fields in tables are public; they can be referred to from everywhere.
• Fields in tables can be referred to directly; for example, in a report, whereas variables in a method can only be referred to using accessor methods.
Table Code
The following example illustrates how table code differs from code for a class.
str text;
text =; // Fields in a table are public
print; // Fields in a table can be referred to directly

X++ Attributes In Ax2012

X++ Attributes
MDAX-2012 supports attributes being assigned to X++ code. This allows for a rich set of metadata to be built. It describes methods and types that are defined within X++ code. Attributes are defined as classes that are derived from the SysAttribute class. The following code for the SampleAttribute class is an example of an attribute class:
public class SampleAttribute extends SysAttribute
str sMetadata; // A field in classDeclaration.
public str GetMetadata()
return sMetadata;
public void new(str _sMetadata)
sMetadata = _sMetadata;
Attributes can then be used on other classes and methods. The following example shows the structure of a new Attribute class, AuthorAttribute:
class AuthorAttribute extends SysAttribute
str author;
public str Author()
return author;
public void new(str _author)
author = _author;
In the following example, AuthorAttribute is used to decorate other classes and methods:
public class MyClass()
void MyMethod()

FactBoxes In Ax2012

A FactBox is a small selection of data related to the current record in the list page.
Three types of Factbox exist:
• Info part: This has its own data source and a number of controls. It is limited in what can be displayed. However it is simple and quick to create, and can also be displayed in the Enterprise Portal.
• Form part: This is a link to a form. The form can have the same controls as a standard form. However since this is displayed in the FactBox section of the list page, adding too many controls can crowd the part.
• Cues: This is a count of a number of records related to the current record in the list page. For example, it might show the number of outstanding invoices for a customer.

Form Templates In AX2012

Form Templates Some form templates are available to help create the correct form type with the appropriate controls, and to keep the design consistent across the application. The following table shows the available form templates and where they should be used.
Examples of Templates
The following table gives examples of each form template

To create a form using a template, right-click the Forms node in the AOT, select New Form From Template, and then select the template. Try to create each template and examine the controls and design that is created.

Table Relations (Normal , Related Field Fixed , Field Fixed)

Table Relations (Normal , Related Field Fixed , Field Fixed)
Lets say you have ClothesTable and ClothesOrders.
ClothesTable has the following fields: ClotheId, Name and CollectionTypeId
ClothesOrder has the following fields: OrderId, ClotheId, Qty OrderId could be a number sequence and Qty entered manually bby the user.
CollectionTypeId has the following elements:
0 - Men
1 - Women
2 - Children
Example 1: Related Fixed FieldOn MenClothesOrder we create a new relation to ClothesTable and specify the follwing two:
1. Normal = ClotheId to ClotheId (Best practice to specify this on the EDT) and
2. Related Fixed Field 0 = ClothesTable.CollecTionTypeId.
This shows that the lookup to the clothes table should show only clothes with the same ClotheId (point 1) AND clothes that are of type Men (point 2) because the our table deals with order for mens' clothes. We use 0 because Menis element 0 in the Enum.
Example 2: Fixed Field This kinda works the other way round:
Imagine you have a ClothesOrders table (generic) and you have seperate tables for MenClothesTable, WomenClothesTable and ChildrenClothesTable. Fixed field says that the specified normal relation (on ClotheId) to MenClothesTable only works if the CollectionTypeId of the current record is set to 0 (Men) else the relation is disabled.

Thursday, August 30, 2012

What is a Model and how to create them?

A model is a logical grouping of elements within a layer.
Models help in situations where multiple ISV solutions or projects must operate together.
This architecture allows many solutions to co-exist within each layer.
An element can exist in exactly one model in a layer. The same element can exist in a customized version in a model in a higher layer.
New models are easy to create in the MorphX IDE and are applied when modifying or adding objects in the AOT.
Models can be exported, installed, or uninstalled from the model store.
Models are identified by a name and a publisher, and have a set of properties that can be changed, including a version number.
How to create a new Model:
Tools > Model management > Create model.

AX2012 Layer's Modified

AX 2012 Layer's
There are three layers available only to Microsoft to deliver the base application. (The xxP layer indicates the patch layer for each application object layer).
SYS, SYP:- System layer: The standard application is developed in this lowest layer. This includes the core application and the localization for most countries.
GLS, GLP :- Globalization layer: Includes features developed for some countries that were not yet moved into the SYS layer.
FPK, FPP :-Feature Pack layer: Includes industry feature packs that are controlled by Microsoft.
There are three layers available to partners and ISVs.
SLN, SLP :- Solution layer: Includes Microsoft endorsed industry solutions.
ISV, ISP :- Independent Software Vendor layer: Includes generic or vertical solutions developed by ISV's.
VAR,VAP :- Value Added Reseller layer: Includes multi-customer solutions developed by VAR's.
There are two layers available to both partners and customers who have a license to access the AX source code.
CUS, CUP :- Customer layer: Includes customer specific functionality.
USR, USP :- User layer: Includes installation specific functionality and customizations.


Monday, July 23, 2012

Copying License in Dynamics Ax

Axapta stores the License data in the following two tables.
So if you copy data of these tables(from Running instance) and import at your instance , this will serve your purpose.

X++ code to create and post Inventory Movement Journal

Following is the sample job to show how we can create and post movement journal by
making use of available api's in the Dynamics Ax.
static void createMovJournal(Args _args)
{ InventJournalTable journalTable;
InventJournalTrans journalTrans;
InventJournalTableData journalTableData;
InventJournalTransData journalTransData;
InventTable inventTable;
InventDim inventDim;
Counter cnt;
InventJournalCheckPost journalCheckPost = new InventJournalCheckPost();
journalTableData = JournalTableData::newTable(journalTable);
journalTransData = journalTableData.journalStatic().newJournalTransData(journalTrans,journalTableData);
// Init JournalTable
journalTable.JournalId = journalTableData.nextJournalId();
journalTable.JournalType = InventJournalType::Movement;
journalTable.JournalNameId = journalTableData.journalStatic().standardJournalNameId(journalTable.JournalType);
// Init JournalTrans
select firstonly inventTable;
journalTrans.TransDate = systemdateget() + 1 div 2;
journalTrans.ItemId = inventTable.ItemId;
journalTrans.Qty = 100;
journalTrans.CostAmount = 100;
// Dimension details
inventDim.InventLocationId = 'GW';
journalTrans.InventDimId = InventDim::findOrCreate(inventDim).inventDimId;
// Call the static method to post the journal

X++ Code to find OnHand Stock for Item

In Dynamics Ax , use InventOnHand class for finding the stock of an item as shownbelow
static void findOnHand(Args _args)
InventDim inventDim;
InventDimParm inventDimParm;
Itemid itemid;
InventOnHand inventOnHand = new InventOnHand();
// take a sample item for testing
itemid = "20 MM RMC";
// take a combination of dimension , against which you want to find the stock
inventDim.InventLocationId = "GW";
//Set the flag for the selected dimensions as active.
//initialize the inventonhand with item,dimension and dim paramter
// Retrieve the onhand info
info(strfmt("Available Physical: %1",
info(strfmt("On order: %1",inventOnhand.onOrder()));

X++ code to find the Stock of Item by Date

static void findOnHand_ByDate(Args _args)
InventDim inventDim;
InventDimParm inventDimParm;
Itemid itemid;
InventOnHand inventOnHand = new InventOnHand();
InventSumDateDim inventSumDateDim;
TransDate transDate;
// take a sample item for testing
itemid = "20 MM RMC";
transDate = 13\01\2010;
// take a combination of dimension , against which you want to find the stock
inventDim.InventLocationId = "GW";
//Set the flag for the selected dimensions as active.
//initialize the inventSumDateDim with Date,item,dimension and dim paramter
inventSumDateDim = InventSumDateDim::newParameters(transDate,
// Retrieve the onhand info
info(strfmt("PostedQty: %1",inventSumDateDim.postedQty()));
info(strfmt("DeductedQty: %1",inventSumDateDim.deductedQty()));
info(strfmt("ReceivedQty: %1",inventSumDateDim.receivedQty()));

X++ code to create a customized lookup on form

Override the lookup method on Formdatasource field(on which you want to show lookup) , and copy the following code to your method.
Comment the super() method in the lookup.
public void lookup(FormControl _formControl, str _filterStr)
SysTableLookup sysTableLookup; // systemclass to create //customlookup
Query query;
QueryBuildDataSource qbd;
sysTableLookup = SysTableLookup::newParameters(
// Construct query on the table,
// whose records you want to show as lookup.
query = new Query();
qbd = query.addDataSource(tablenum(InventTable));
// add the fields to the lookup list
// pass the query as parameter
// system will show the records in the lookup
// as per your query

Get AX4.0 look and feel back in Ax2009

You all might be aware that all forms in Ax2009 are behaving like independent application forms.i,e When you open any form it will get open outside the application.
So following are the two solutions to open forms in same workspace as in Ax4.0
1. Change the formdesign property windowtype(from standard to workspace).this you have to do for all the forms which is time cosuming.
2. Or else Add following line in the init method of SysSetupFormRun class. before super() as shown in the following code
public void init()
//at run-time you are setting property to workspace.
if (this.isWorkflowEnabled())
workflowControls = SysWorkflowFormControls::construct(this);

X++ code to hide content pane in ax2009

This is for developers , not for endusers.As you know it will irritate during developemnt since it is appearing on top of all windows when we open form.
static void hideContentPaneWindow(Args _args)
HWND contentPane = WinApi::findWindowEx(WinAPI::findWindowEx(infolog.hWnd(),
0, 'MDIClient', ''),0,'ContentFrame','' );
if (contentPane)
WinApi::ShowWindow(contentPane,#SW_HIDE); // To restore use #SW_RESTORE

How to Use Temporary Table in Form

Temporary table(Table whose property temporary set to "yes") is not persistent media , so at run-time you have to populate the temporary table and attach the same to the form/report. For illustration purpose ,I am using inventTable data and attaching the items whose group is Parts.
1. Create temporary table as TmpTestTable with 3 fields(ItemId,Itemname,ItemGroup).
2. Create a form as TempTestTable and attach the table as datasource
3. Create a new method on the form and copy the following code
TmpTestTable populateRecords(ItemGroupId _itemGroupId)
TmpTestTable tmpTable;
InventTable inventTable;
while select inventTable
where inventTable.ItemGroupId == _itemGroupId
tmpTable.Itemid = inventTable.ItemId;
tmpTable.ItemName = inventTable.ItemName;
tmpTable.Itemgroup = inventTable.ItemGroupId;
return tmpTable;
4. Call the above method in init() after super as below public void init()
// Call the setTmpData method to attach records to datasource

How to use Dialog in Dynamics Ax.

If you came accross a requirement , where you need to collect the information and then executes a task . In such scenario Please make use of RunBase class.
Advantage of RunBase class
1. It provides dialog for presenting and collecting the information from user.
2. Pack/Unpack methods , for storing the last value entered by the user.
3. Progress bar ,for long time process where in you can show a progress bar.
4. Validate method , to validate the data entered by the user in the dialog.
you can refer tutorial in AOT->Classes->tutorial_RunBaseForm .

X++ code to identify multiple selected records in Grid

Steps : 1. Create a new method on form and copy the following code. 2. Next create a button on form . and call the method on the button click event. (for the button property makesure the Multiselect should be set to yes , or else by default for multiple selection system will disable the buttons)
void checkSelectedRecords()
InventTable inventLocal;
//getFirst method gets all the selected records in the grid
inventLocal = InventTable_ds.getFirst(true);
while (inventLocal)
info(strfmt("You selected Item %1",inventLocal.ItemId));
// get the next selected record
inventLocal = InventTable_ds.getNext();

Tuesday, January 17, 2012

How to set Default Order Settings for an Item??

How to set Default Order Settings for an Item??
static void Set_DefaultOrderSettings(Args _args)
InventTable inventTable;
InventItemInventSetup invent;
InventItemPurchSetup purch;
InventItemSalesSetup sales;
delete_from invent;
delete_from purch;
delete_from sales;

while select inventTable

If you have deleted the Item master and imported with new items then run this job to automatically insert the default order settings for the all items..
Otherwise system will not allow u to create any item transactions it will give error like"No Item parameter for the item"..
Enjoy DAXing :)-

Tuesday, January 3, 2012

How to extract Date value from a DateTime field?

How to extract Date value from a DateTime field:
static void getDate(Args _args)
System.DateTime _dateTime;
Date _date;
PurchTable _purchTable;
_purchTable = PurchTable::find("PO000008");
_dateTime = System.DateTime::Parse(dateTime2str(_purchTable.createdDateTime));
_date = _dateTime.get_Date();
static void getDate(Args _args)
System.DateTime _dateTime;
Date _date;
PurchTable _purchTable;
InteropPermission intPerm = new InteropPermission(InteropKind::ClrInterop);
_purchTable = PurchTable::find("PO000008");
_dateTime = System.DateTime::Parse(dateTime2str(_purchTable.createdDateTime));
_date = _dateTime.get_Date();
Simply :)-
Instead of the third and second last lines you could use:
_dateTime = DateTimeUtil::date(_purchTable.createdDateTime); for the same result.

Difference between Transfer Journal ,Transfer Order and Stock Transfer?

What is the difference between a transfer journal and a transfer order?
A) With the help of the transfer journal, the Inventory Manager transfers the items from one dimension (warehouse, location, color, etc) to another one instantaneously.

The transfer order is used for registering in the system the items that must be moved from one warehouse to another and for managing this process.

Process Includes:
Create Transfer Order
Pick Items to Transfer->then->Picking list registeration
Pick Items to Transfer(No Picking list registeration)
Ship Transfer Order
Receive the Items at other end.

What is the difference between a transfer Order and Stock tranfer?
A) For Indian Localization taxation, Microsoft Included Stock transer.It will Includes taxes on the Item in the transfer Process(Create Stock transfer,Pick,ship,receive)