Skip to main content

Add fields for table/field mapping during an upgrade

In my recent upgrade project that I took over in the middle of the upgrade process I had to use a small trick to fix many table and field mappings errors in the Data upgrade checklist




static void addFields(Args _args)
{
    TreeNode                            treeNode;
    AOTTableFieldList                   fieldList;
    #AOT
   
    ReleaseUpdateBulkCopyField          fields;
    ReleaseUpdateBulkCopyTable          tables;
    DEL_SqlDictionary                   del_sql;
    SqlDictionary                       sql;  

    str                                 newTableName;
    str                                 newFieldName;
    ;

    while select RecId from fields
    join OldTableName, NewTableName from tables
        where fields.Status == ReleaseUpdateBulkCopyFieldStatus::NoMapping
        && fields.OldTableId == tables.oldTableId
    join FieldType, StrSize from del_sql
        where fields.OldTableId == del_sql.TabId
        && fields.OldFieldSqlName == del_sql.SqlName
    {
        newFieldName = '';

        select fieldsData where fieldsData.RecId == fields.RecId;

        if (fieldsData.OldFieldName == 'CREATEDDATE')
            newFieldName = 'DEL_CreatedDate';

        if (fieldsData.OldFieldName == 'MODIFIEDDATE')
            newFieldName = 'DEL_ModifiedDate';

        if (newFieldName != '')
        {
            newTableName = tables.newtablename;

            treeNode = TreeNode::findNode(@'\\Data Dictionary\Tables\' + newTableName);
            fieldList = treeNode.AOTfindChild('fields');
            fieldList.addDate(newFieldName);

            SqlDataDictionary::synchronize();
        }
    }  

    info('Done');
}

Comments

Popular posts from this blog

2012 Enterprise Portal Development Cookbook

Yes it is here, the most interesting book of the year " Microsoft Dynamics AX 2012 Enterprise Portal Development Cookbook " Check it out my friends http://blogs.msdn.com/b/solutions/archive/2012/07/12/microsoft-dynamics-ax-2012-enterprise-portal-development-cookbook.aspx

Dynamics 365 for operations – Table extensions

Background Extensions are a new way to add functionality and custom code to the D365 system without changing the standard code. In fact, Microsoft has announced that edit standard elements like those that we have done in the past will not be possible after 2017. By using extensions, we can achieve the same result by simply extending the standard system => EXTENSIONS. To read more about the difference between overlaying and extensions follow this link https://ax.help.dynamics.com/en/wiki/customization-overlayering-and-extensions/#extensions Extending tables By using table extensions, we can create a new table that adds new fields, field groups, indexes, mappings, relations, methods, subscribe to event handlers and more. When extending tables we need to follow the naming rule as such: <TABLENAME><_Extension> the compiler understands the _Extensions suffix and knows that the table in question is extending a table from the standard system. This gives us access ...

SysOperationFramework

I have tried out the new SysOperationFramework of Dynamics Ax 2012 that is going to replace the old RunBase framework. The SysOperationFramework is service based batch framework and it is my feeling at the moment that it will provide us with more possibilities for creating and setting up batch jobs in the real world. There is no need for me to create a full blog about the SysOperationFramework since I am not the first one to try this out. So i will simply refer to another blog post about the SysOperationFramework  http://www.artofcreation.be/2011/08/21/ax2012-sysoperation-introduction/ Thanks to Art Of Creation – Dynamics AX Blog for an outstanding good blog post on the matter Happy batch programming my friends