Thursday, March 28, 2013

Export and Import a Model In Dynamics AX 2012


Export an .axmodel file (Windows PowerShell)

  1. On the Start menu, point to All Programs, point to Administrative Tools, and then click Microsoft Dynamics AX Management Shell.
  2. At the Windows PowerShell command prompt, PS C:\>, type the following command, and then press ENTER.
    Export Command Syntax :
    Export-AXModel –Model <name> -File <Filename.axmodel>
    Example : 
    Export-AXModel –Model SecurityModel -File C:\SecurityModel.axmodel


Import an .axmodel file (Windows PowerShell)
    1. On the Start menu, point to All Programs, point to Administrative Tools, and then click Microsoft Dynamics AX Management Shell.
    2. At the Windows PowerShell command prompt, PS C:\>, type the following command, and then press ENTER.
    Import Command Syntax :
    Install-AXModel -File <Filename.axmodel> -Details
    Exmaple :
    Install-AXModel -File C:\SecurityModel.axmodel -Details

Tuesday, March 26, 2013

How to Filter records in form by X++ code

The standard filter functionality in Ax forms is a neat and powerful feature.
Using this filter functionality in your code is something you'll definitely use at some point in time as a programmer.

Although it's possible to do it in a single line of code, I prefer a 3 step solution. That way it's more flexible.
Let me show you by example. We'll filter the customers records in form CustTable, only showing customers with currency USD.

Step 1: Declare a class variable
In the ClassDeclaration method of the form, define a range.

QueryBuildRange CurrencyQBR;

Step 2: Instantiate the new range.
In the init method on the datasource of the form, you assign the range to a specific field (after the super call).

public void init()
{
super();

CurrencyQBR = this.query().dataSourceName('CustTable').addRange(fieldnum(CustTable,Currency));
}

Step 3: In the last step, you assign a value to the range.
This is done in the executeQuery method on the same datasource of the form. Before the super call. Like this:

public void executeQuery()
{ ;

CurrencyQBR.value(queryvalue('USD'));

super();
}

You're done! When you open the form, your customer records are filtered, you only get the customers with currencycode USD set up.




Like I said in the intro of this post, this can be done in one line of code as well.
In the init method of the form datasource, after the super call, place this code:

this.query().dataSourceName('CustTable').addRange(fieldnum(CustTable,Currency)).value(queryvalue('USD'));
But this way, it's fixed. If you choose the 3 step method, you could for example use a variable in the range value. The way to go would be to place an input field on your form, get the value from it and supply it in the executeQuery method.
For example like this:
public void executeQuery()
{ ;

CurrencyQBR.value(queryvalue(MyInputField.text()));

super();
}

Just make sure the executeQuery method is executed, thus applying the desired filter (maybe be using a button on your form to activate it).
Of course it's possible to combine multiple querybuildranges.

Monday, March 25, 2013

AX2012 R2 Setup Step by Step....



Dear Friends,


As you know the much awaited AX 2012 R2 is launched so Here we have a install/upgrade overview on AX 2012 R2 in just 24 clicks :

1) Start the Setup Program.

 2) Click "Microsoft Dynamics AX Components" under Install.


 3) Click Next.


 4) Select "I accept the license terms" *.


 5) Choose Appropriate Option.


 6) Processing will start.




 7) Choose "Add or modify components".

 8) Select Options to install/upgrade.

 9) Review the Errors/warnings and click on "Configure" check box for the applicable errors. and click "Configure".

 10) Click "Start" to start configuring components as per AX needs.

 11) Select "Configure existing database (for upgrade scenarios)".

 12) Specify your existing databases.

 13) Choose models to upgrade.

 14) Specify the "Temp" location for setup files.

 15) Specify the SSAS details.

 16) Specify credentials (we just have used the dummy account) for learning purpose only. Use your AD authenticated account details.

 17) Specify .net BC account (if its not already there in AX)

 18) Choose your Languages (en-US) in this demo.

 19) Specify Data Crawler Account details.


 20) SSRS Database details.



 21) User Account for SSRS Access. Click Next

23) Review prerequisite validation & Click Next.



23) Click Install.

24) Verify the installation.


Enjoy DAXing......... 

Wednesday, March 20, 2013

Custom Lookup in Dynamics AX 2012

As a Dynamics AX developer, you'll often have to perform custom lookups. Meaning that the user may only select records in another table depending on some condition on the form, or elsewhere.


Now, to create a custom lookup, we'll use the class SysTableLookup as it provides us a set of methods to do so.

Here's our method, to be created directly on the table CustTable, with some CustGroup.


With that little piece of code, Dynamics AX will already display a lookup form with the table you've specified as a DataSource, displaying the fields you specified with the method addLookupField and following the results criteria of the Query you've passed to it.

Now all we have to do is actually call our lookup method, by overriding the lookup of the correct field in our Form's Data Source:


And that's it! The lookup will be performed. But there's one additional step we'll have to take here...

Dynamics AX will display the results of the query, based on the filter we've created. So the user will only be able to see what we want him to see, and so he'll only be able to select what we want. The problem is that if he types in an existing record for the CustTable in the control, even if does not get shown in our lookup, Dynamics AX will accept that.

To avoid that the user does in fact type in something we don't want, we'll have to override the validate method for our field in our Data Source. The simplest logic is to check if the CustTable record the user typed in does attend the filter we've specified:


You also need to write find method on CustTable that you call in validate method.


So if the user simply types in for a record that does not attend our filter, Dynamics AX won't let the user save that value.

Happy DAXing....... :)


How to Create Primary Key Table in AX 2012


Follow below steps to create primary key in a table in AX 2012. It can consist of single field only. You can not use more than one fields. If you use more than one fields than it will only appears in Cluster Index Property.

1) Create the Table and add required fields to the table as you all knows.
2) Create an Index by dragging the required field to the Index.
3) Set the following Index properties:
        a) AllowDuplicates to "NO".
        b) Alternate key to "YES".
4) Set the  PrimaryIndex  property of the table to newly created index after creating the Index.

Enable UAT database over OneBox DevTest environment using JIT

 Dear Friends, In this Article I will show you how to enable UAT database access for Development machine using just-in-time (JIT). Many time...