Monday, November 26, 2012

Lookups on Dialog: SysTableLookup and registerOverrideMethod

SysTableLookup can be used in dialogs to create custom lookups.
control.registerOverrideMethod can be used to register the methods to override by an object
Here is the example which shows basic usage of both. We will create a dialog and get a lookup of account numbers on a control
protected Object dialog()
{
    FormStringControl control;
    ;

    dialog = super();
    dialogFeildAccountNum = dialog.addField(extendedTypeStr(AccountNum));
    control = dialogFeildAccountNum.control();
    control.registerOverrideMethod(methodStr(FormStringControl, lookup), methodStr(DialogLookup, accountNumLookup), this);
   
    return dialog;
}
Here is the method:
private void accountNumLookup(FormStringControl _control)
{
    SysTableLookup          sysTableLookup;
    QueryBuildDataSource    queryBuildDataSource;
    Query                   query = new Query();

    queryBuildDataSource = query.addDataSource(tablenum(CustTable));

    sysTableLookup = SysTableLookup::newParameters(tablenum(CustTable), _control);
    sysTableLookup.addLookupfield(fieldnum(CustTable, AccountNum),  true);
    sysTableLookup.parmQuery(query);
    sysTableLookup.performFormLookup();
}

DictEnum class in AX2012


The DictEnum class obtains meta-information about the base enumeration enumerations in the AOT.
This can be used when you want to access an enum properties or values at run time.
Can be initialized as below:
DictEnum            dictEnum;
dictEnum = new DictEnum(enumNum(DMFEntityType));

Now we are ready to all properties of enum DMFEntityType

dictEnum.value2Label(i)- Retrieves the label of a specified enumeration value. ‘i’ being the enumeration value

dictEnum.index2Label(i) - can be used in a for loop where ‘i’ being the iterator index value.  This will retrieve the label of the enumerator at specified index.
dictEnum.index2value(i) - can be used in a for loop where ‘i’ being the iterator index value.  This will retrieve the enumerator value of the enumerator at specified index.

RecordInsertList class in AX2012


The RecordInsertList class allows to insert multiple records in to database.

new() - Creates a new object to hold records for insertion into the database.
add() - Adds a record to a RecordInsertList object for subsequent insertion into the database
insertDatabase() -  Inserts all records, that have not already been inserted, in the current 
RecordInsertList object.  


The following example uses the RecordInsertList class to copy records from one table buffer to another.
void copyBOM(BOMId _FromBOM, BOMId _ToBOM)
{
    RecordInsertList BOMList;
    BOM BOM, newBOM;

    BOMList = new RecordInsertList(tableNum(BOM)); 

    while select BOM
    where BOM.BOMId == _FromBOM
    {
        newBOM.data(BOM);
        newBOM.BOMId = _ToBOM;
        BOMList.add(newBOM); 
     }
    BOMList.insertDatabase(); 
}

Tuesday, November 13, 2012

Data Migration framework User guide and download

Data migration framework user guide:
http://technet.microsoft.com/en-us/library/jj225591.aspx

You can download the tool at Information source. Login using your partnersource account to download.
You can also look at the demo video on the link.

Friday, November 9, 2012

Importing conflicting models in AX 2012


Import an .axmodel file using Microsoft dynamics AX2012 Management shell:

Open the Microsoft dynamics AX2012 Management shell from Adminitrative tools.
At the command prompt, type the following command, and then press ENTER.
axutil import /file:<filename> 
This command installs the specified file in the same layer that it was exported from.

If the installation fails because of a conflict and still you want to import the model to resolve conflicts,you can rerun the command, and use the /conflict:push option to push the element that has the conflict to the related update layer. You can then resolve the conflict. 
axutil import /conflict:push /file:<filename>