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;
}
}
}
If you found value in what I share, I've set up a Buy Me a Coffee page as a way to show your support.
Buy Me a CoffeeNo comments. Be the first one to comment on this post.
DaxOnline.org is free platform that allows you to quickly store and reuse snippets, notes, articles related to Dynamics 365 FO.
Authors are allowed to set their own "buy me a coffee" link.
Join us.