Friday 15 July 2016

Create MorphX Report in Ax

We're already aware of MorphX environment of Microsoft Dynamics Ax. The MorphX reports are very easy to delevelop than SSRS reports. SSRS reports are developed in visula studio while MorphX report are developed inside Microsoft Dynamics Ax (MorphX Environment) that's why these reports are named as MorphX reports or sometimes Ax Reports.

Here I would tell you step by step development of a demo MorphX report.
This example is to pick all the sales order records related to one customer. If you want to print all customer's records than don't select any parameter.
  • First of all create a new report and add it to your project.

  • Add CustTable to Report datasource
  • Now expend CustTable datasource and add SalesTable to inside CustTable datasource.
  • In salesTable datasource create a relation as shown below that will only pick those records where customer account in CustTable is equal to customer account in SalesTable. 
                                      
  • Right click on Report Design and select Generate Design. By this CustTable and SalesTable section would be automatically created in your report's design. 

  • Inside 'Section Group : CustTable', right click on 'Body: CustTable_body', select new control 'Field form CustTable' and add AccountNum and Name fields to body.

  • Similarly. add SaleTable Fields whichever you want to Body:SalesTable_body. I have added Salesid, QuotationId, CreatedDateTime, SalesSatatus. deliveryAddress and CurrencyCode.

  • Now open your report and select any customer

  • After following all the above steps successfully your report output would be as shown below.


Note: I didn't focus on report's design much so this report looks very simple. You can customize this report according to your requirement, you can also make changes for individual control's properties such as size, caption, width-height, margins, position, label etc. After changing control properties you can make your report more attractive.
If you want to use table's display methods in your report than write that display method name in data method property.

In case you have any doubt do comment below. Thank you so much. 


Thursday 19 May 2016

Create New Table On New Record Creation Of Another Table

This post will help you if you have requirement to create a new record every time when a new record is created in another table.

Let me explain this with an example:
Assume that you have a master table 'Bank_Account' which contains a field 'AccountNumber'. Now the requirement is  when a new Account Number is added (created) related to this Account Number a new table should be created as 'Transaction_####'. The name of the Transaction_#### would be dynamic.
If the Account Number is 1001 then Transaction_#### name should be Transaction_1001.

Follow the below steps:

  • Create a table Bank_Account
    • Add a field Account_Number (String)
    • Set properties Mandatory : Yes , Allow Edit : No
    • Make Account_Number as a Primary Key 
      • PK : Go to Index node > New Index

    • Field AccountNumber has now become primary key.

  • Override modified field method in table Bank_Account and write following code.
 public void modifiedField(FieldId _fieldId)
{
    SysDictTable sysdictTable;
    Treenode treenode;// its a class
    AOTTableFieldList fieldnode;
    str Prefix,Acc,Tablename,prop;
    int pos,Account_NumberID;
    #AOT
    #Properties
    ;

    Account_NumberID = fieldNum(Bank_Account, Account_Number); // Getting Account_Number field ID
    super(Account_NumberID);
    this.insert();
    Prefix = "Transaction_";
    Acc = this.Account_Number;
    TableName= Prefix + Acc;

//#Table path refer the \\Data Dictionary\\Tables and finding the path
treenode = treenode::findNode(#TablesPath);
//AOTadd method is to add table in tables//TableName is table name
treenode.AOTadd(Tablename);
treenode = treenode.AOTfindChild(TableName);
treenode.AOTcompile(1);
treenode.AOTsave();
treenode.AOTfindChild(TableName);
fieldnode = treenode.AOTfirstChild();
fieldnode.addString('AccountNum');
fieldnode = fieldnode.AOTfindChild('AccountNum');
prop = fieldnode.AOTgetProperties();
pos = findPropertyPos(prop,#PropertyExtendeddatatype); //find right place to put extended data type
pos = strFind(prop,'ARRAY',pos,strLen(prop));
pos = strFind(prop,'#',pos,strLen(prop));
fieldnode.AOTsetProperties(prop);
treenode.AOTcompile(1);
treenode.AOTsave();
treenode.AOTRestore(); //to load assigned extended data type properties
sysdictTable = sysdictTable::newTreeNode(treenode);
appl.dbSynchronize(sysdictTable.id());

}


  • Override insert method of table Bank_Account and write following code

public void insert()
{
    super();
    info("NewTable " + "Transaction_" + this.Account_Number + " has been created");
}

  • An Account is added into Bank_Account










  • Now go to AOT > Table node , a new table named 'Transaction_101' has been created.














                     ThanYou !

Create Table Using X++ Code

static void autoTable(Args _args)
{
SysDictTable sysdictTable;
Treenode treenode;
AOTTableFieldList fieldnode;
str prop;
int pos;
#AOT
#Properties
;
//Coded by Gautam Verma

//#Table path refer the \\Data Dictionary\\Tables and finding the path
treenode = treenode::findNode(#TablesPath);
 
//AOTadd method is to add table in tables//AutoTableis table name
 
treenode.AOTadd('AutoTable');
treenode = treenode.AOTfindChild('AutoTable');
treenode.AOTcompile(1);
treenode.AOTsave();
treenode.AOTfindChild('AutoTable');
fieldnode = treenode.AOTfirstChild();
fieldnode.addString('AccountNum');
fieldnode = fieldnode.AOTfindChild('AccountNum');
prop = fieldnode.AOTgetProperties();
pos = findPropertyPos(prop,#PropertyExtendeddatatype); //find right place to put extended data type
pos = strFind(prop,'ARRAY',pos,strLen(prop));
pos = strFind(prop,'#',pos,strLen(prop));

fieldnode.AOTsetProperties(prop);
treenode.AOTcompile(1);
treenode.AOTsave();
treenode.AOTRestore(); //to load assigned extended data type properties
sysdictTable = sysdictTable::newTreeNode(treenode);
appl.dbSynchronize(sysdictTable.id());
}

                     ThanYou !


Tuesday 17 May 2016

Joins In Microsoft Dynamics Ax

There are basically four types of joins in Ax,
  1.  Inner Join
  2. Outer Join 
  3. Exists Join
  4. Notexists Join
Inner Join : Inner Join will return records from both Outer table and Inner table, only the records which are available in Inner table. Inner Join will also return duplicate records.

Outer Join : Outer Join will return all the records from both Outer table and Inner table. Outer Join will also return duplicate records.

Exists Join : Exists Join will return records only from Outer table which are available in Inner Table. It will not return any duplicate records. 

NotExists Join : NotExists Join will return records only from Outer table which are not available in Inner Table. It will not return any duplicate records.

So now you are clear with the definitions of multiple types of joins in ax. To understand how practically it works use the following steps.

  • First of all create two tables in Dynamics Ax Demo_Outer and Demo_Inner.
  • In Demo_Outer table create two fields
    • Account (PK)
    • Name
  • In Demo_Inner table create two fields
    • Account (FK)
    • Phone
  • Insert some records in both the tables



























To test the joins create a job and fetch records from tables by using code.

Inner Join : Write the following code to test inner join.

static void Demo_Joins(Args _args)
{
    Demo_Outer demo_Outer;
    Demo_Inner demo_Inner;
    while select demo_Outer
          join demo_Inner
        where demo_Inner.Account == demo_Outer.Account
        {
            info(demo_Outer.Account +" :: "+ demo_Outer.Name +" :: "+ demo_Inner.Phone );
        }

}

Inner Join Output :
Inner Join


Outer Join : Write the following code to test outer join.

static void Demo_Joins(Args _args)
{
    Demo_Outer demo_Outer;
    Demo_Inner demo_Inner;
    while select demo_Outer
       outer join demo_Inner
        where demo_Inner.Account == demo_Outer.Account
        {
            info(demo_Outer.Account +" :: "+ demo_Outer.Name +" :: "+ demo_Inner.Phone );
        }
}

Outer Join Output : 
Outer Join



















Exists Join :  Write the following code to test exists join.

static void Demo_Joins(Args _args)
{
    Demo_Outer demo_Outer;
    Demo_Inner demo_Inner;
    while select demo_Outer
       exists join demo_Inner
        where demo_Inner.Account == demo_Outer.Account
        {
            info(demo_Outer.Account +" :: "+ demo_Outer.Name +" :: "+ demo_Inner.Phone );
        }
}

Exists Join Output : 


Exists Join













NotExists Join : Write the following code to test notexists join.

static void Demo_Joins(Args _args)
{
    Demo_Outer demo_Outer;
    Demo_Inner demo_Inner;
    while select demo_Outer
       notexists join demo_Inner
        where demo_Inner.Account == demo_Outer.Account
        {
            info(demo_Outer.Account +" :: "+ demo_Outer.Name +" :: "+ demo_Inner.Phone );
        }

}

NotExists Join Output : 
NotExists Join














                  Thank You !



Monday 18 April 2016

How to use Display Method in AX

Sometimes developer has requirement to show data on selecting some record. This can be achieved using display method. It saves memory space as we don't need to insert record in another tables to use data. Here I'm giving an simple example on how to use display method in axapta.

Example:

  • Crate two tables TableA and TableB
  • Create two fields in TableA Id and Name.
  • Create a field in TableB Id.
  • Now create a relation as shown below.




  • Create a display method getNameMethod and write following code.


  • Now create a Form to test display method
  • Add TableB in Data Source of form
  • Drag Id field to design and create new string field Name and change property.
  • Make DataSource as TableB and DataMethod as getNameMethod.

  • Insert some dummy records in Table.











  • Now open form and select any record.

















  • Here name is coming automatically using display method.












  • Similarly, you can also try with some standard table.
Note : In example Axapta 4.0 version (2006) is used.