Home > Ax Technical > Solving the Id conflict issue during import of XPO in Dynamics Ax

Solving the Id conflict issue during import of XPO in Dynamics Ax

When you try to import an XPO with an Id conflict(Two different components sharing the same name), then Ax prompts with an dialog. This dialog informs the conflict and skips importing the specific component.

This is specifically more trouble some when you are developing application connected to TFS. Especially when you synchronize an component with ID conflict the synchronize skips it and to get the object again you will have to either do a Checkout/checkin from another machine or do a forced synchronize. So i was often made to spend more time because of these issue.

To avoid this after some time i developed a small workaround that worked well and served the cause. Here it goes…

it is basically the following line which makes the call to the function that imports as well as show the dialog.

\Classes\SysImportElements\importElements – Line 51

“flag = infolog.importElement(_exportId, tmpImportAot.UtilFileType, tmpImportAot.UtilElementType, name, tmpImportAot.FilePos, flag);”

What i did was built a small condition that validates if there is any existing component with the same Id and if so, then it asks the user if it can delete and import the new one. If yes then it deletes the existing one and then imports the new component. This way the dialog allows you to perform an action rather being just an blocking prompt information.

Here is the code which does the job.
For the purpose of convenience i added this as an method that returns a boolean variable and modified the actually call with an if condition.

//This method is helpful in finding ID conflicts earlier.
//Through this method we can avoid the VSS error where an element is updated in the file system but not in the AOT
protected boolean I4C_validateImport(TmpAotImport _tmpImportAot)
{
    UtilIdElements elements;
    str            userString;
    TreeNode        node;
    TreeNode        parentNode;
    ;

    select firstonly elements
           where     elements.id            == _tmpImportAot.UtilElementId   &&
                     elements.recordType    == _tmpImportAot.UtilElementType &&
                     elements.name          != _tmpImportAot.TreeNodeName;

    if (elements.RecId)
    {
        userString  = strfmt("Importing AOT object '%2' with Id %1  is already occupied by element '%3'. Do you want to delete the existing tree node object '%3' and import '%2'? Cancel will abort the import.",
                             _tmpImportAot.UtilElementId, _tmpImportAot.TreeNodeName, elements.name);
        if (DialogButton::Ok == Box::okCancel(userString, DialogButton::Ok, "Id conflict"))
        {
            node = xutilIdElements::getNode(elements);
            if (node)
            {
                node.AOTdelete();

                parentNode = TreeNode::findNode(SysTreeNode::pathParent(node.treeNodePath()));
                if (parentNode)
                {
                    parentNode.AOTrefresh();
                }

                return true;
            }
        }

         return false;
    }

    return true;

}

And modify the code in the following location as show below

\Classes\SysImportElements\importElements – Line 51

if (this.I4C_validateImport()
{
    flag         = infolog.importElement(_exportId, tmpImportAot.UtilFileType, tmpImportAot.UtilElementType, name, tmpImportAot.FilePos, flag);
}
Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: