Dynamics Search Engine

Thursday, June 5, 2008

How to open Dynamics Ax form through X++ code

This article shows how to open forms in Dynamics Ax through X++ code.
Note: Use at your own risk.
You should be familiar with X++ basic programming.

I applied it on Dynamics Ax 3.0

1) Open your Ax application then AOT.
2) Go to Jobs node and create a new job.
3) Add the following codes in your job to open a form by menuitem name.

MenuFunction menuFunction;
;
menuFunction = new MenuFunction(MenuItemDisplayStr(CustTable), MenuItemType::Display);
menuFunction.run();

Your job will look like:

static void Job1(Args _args)

{
MenuFunction menuFunction;
;
menuFunction = new MenuFunction(MenuItemDisplayStr(CustTable), MenuItemType::Display);
menuFunction.run();
}



You can open your form by form name also.
1) Create a new job.
2) Copy the below code and paste to your job.

static void Job2(Args _args)
{
Args args;
FormRun formRun;
;
args = new Args();
args.name(formstr(CustTable));
formRun = new FormRun(args);
formRun.run();
formRun.wait();
}


Saturday, May 24, 2008

Provide Base Enum name and element number and get the label of that element through X++

In this article you will be aware that how the get the label of an element of a base enum.
Prerequisite: You should have basic programming knowledge of X++.

I applied it on Ax 3.0

You can provide the base enum name directly using global method fieldnum() or you can provide it in a string using method fieldname2id() where you need to give table id and fieldname.

Steps are as below:
1) Open your Ax application then AOT.

2) Go to Jobs node and create a new job. Rename the job if you need. I renamed it to DictEnumElementLabel.

3) Now write the following lines...

static void DictEnumElementLabel(Args _args)
{
DictEnum de;
DictField df;
;
df = new DictField(tablenum(SalesTable),fieldname2id(tablenum(SalesTable),'SalesType'));
if(typeof(df.type()) == Types::Enum) //checks if Type == Enum
{
de = new DictEnum(df.enumId());

info(de.index2Name(3)); // print element label
}
else
info('Not Enum type');
}


4) Now run the job and you will get the label of element of the base enum 'SalesTypes' you specified.

Provide Base Enum name and get the number of elements through X++

In this article I will tell you how the get number of elements of a Base Enum...
Prerequisite: You should have basic programming knowledge of X++.

I applied it on Ax 3.0

You can provide the base enum name directly using global method fieldnum() or you can provide it in a string using method fieldname2id() where you need to give table id and fieldname.

1) Open your Ax application then AOT.
2) Go to Jobs node and create a new job. Rename the job if you need. I renamed it to DictEnumElements.
3) Now write the following lines...

static void DictEnumElements(Args _args)
{

DictEnum de;
DictField df;
;
df = new DictField(tablenum(SalesTable),fieldname2id(tablenum (SalesTable),'SalesType'));

if(typeof(df.type()) == Types::Enum) //checks if Type == Enum
{
de = new DictEnum(df.enumId());
info(int2str(de.values()));
}
else
info('Not Enum type');
}

4) Now run the job and you will get the number of elements of the base enum 'SalesTypes'

Thursday, May 15, 2008

How to browse tables in Dynamics Ax by using X++

This article explains:
How to browse a table runtime in Microsoft Dynamics Ax
How to rbowse a table using x++ language in Microsoft Dynamics Ax
How to browse a table programatically in Microsoft Dynamics Ax
How to open a Microsoft Dynamics Ax table by using X++ codes

Note: You should be familiar with Dynamics Ax basic programming.

Open your Ax application then AOT.
Go to Jobs node and crate a new job.
Copy and paste the code below. Here I renamed the job to BrowseTable.

I applied it on Ax 3.0

static void BrowseTable(Args _args)
{
SysTableBrowser systabB;

;
systabB = new SysTableBrowser();
systabB.run(tablenum(inventtable));
}