Moving a project to another model

If you have:
  • more than one model in your layer
  • the elements in project can belong to more that one model in the same layer
Then do not move the project directly. Moving a project to another Model will also move all elements that project contains.
Method 1:
Create a new Project in the desired Model and then Drag the elements from the original project into this new one.
Method 2:

Please be aware that client in most cases will not show actual model on a project just after successful run. In that case AOS restart is required.

static void UpdateProjectModel(Args _args)
{
    // Project to move
    TreeNode            treeNode = TreeNode::findNode(@"\Projects\Private\PendingObjects");
    str                 g;
    SysModelElement     sysModelElement;
    SysModelElementData sysModelElementData;
    UtilElementType     projectType = UtilElementType::PrivateProject; // Project type, shared/private
    ModelRecId          modelIdFrom = 1662,    // ModelId source
                        modelIdTo   = 11,    // ModelId target
                        modelRecId;
    
    if (!SysModelStore::modelId2Name(modelIdFrom))
    {
        throw error('Incorrect source model id');
    }
    if (!SysModelStore::modelId2Name(modelIdTo))
    {
        throw error('Incorrect target model id');
    }
    
    g = treeNode.AOTgetProperty('Origin');
    if ('{00000000-0000-0000-0000-000000000000}' != g)
    {
        select sysModelElement
            where sysModelElement.Origin        == treeNode.AOTgetProperty('Origin')
                &&sysModelElement.ElementType   == projectType;
        if (sysModelElement.RecId)
        {
            ttsBegin;
            select forUpdate sysModelElementData
                where sysModelElementData.ModelElement  == sysModelElement.RecId
                    &&sysModelElementData.ModelId       == modelIdFrom;
            if (sysModelElementData.RecId && modelIdTo)
            {
                sysModelElementData.ModelId = modelIdTo;
                sysModelElementData.update();
                info(strFmt("Moved from %1 to %2", SysModelStore::modelId2Name(modelIdFrom), SysModelStore::modelId2Name(modelIdTo)));
            }
            ttsCommit;
        }
    }
}


 

Search

About

DaxOnline.org is free platform that allows you to quickly store and reuse snippets, notes, articles related to Dynamics AX.

Authors are allowed to set their own AdSense units.
Join us.

Blog Tags