Friday, 8 February 2013

Delete Private AOT projects in AX 2012

This is a common problem since the old days. People leave projects in their private project and no one can get to it to clean it up.

In pre AX2012, it was a matter of selecting the utilElements and calling the AOTDelete method. I won’t go through it here.

In AX2012, it is all maintained in the model store.

Let see it in pictures.

Below are the projects you want to delete.

Proj2013-01-30_1514

You can see them in the SysModelElement table. It is in the system tables section.

PrivateProj2013-01-30_1513

I wrote a job to loop through and delete them. I had to

Code:
static void deleteAllProjectObjects3(Args _args)
{
/*
msdn.microsoft.com/en-us/library/bb190038(v=ax.10).aspx
*/

SysModelElement sysModelElement;
ProjectNode privatePn;
ProjectNode pn;
utilElementName shortName;
int len;
str preFix;

// Navigate to the Private projects folder.
privatePn = infolog.projectRootNode().AOTfindChild("Private");

preFix = curuserid()+'_';
len = strlen(preFix);


while select sysModelElement
where sysModelElement.ElementType == 38
//&& sysModelElementName like "*TestProj*"
{
// remove <userId>_ from the _projectName to get the name used in the Projects tree for a private project
if (substr(sysModelElement.Name, 1, len) == preFix)
{
shortName = strdel(sysModelElement.Name, 1, len);
}

// Get a reference to the project.
pn = privatePn.AOTfindChild(shortName);

pn.AOTdelete();
}
}



Disclaimer:


Use at your own discretion. No guarantees here.

3 comments:

nathan clouse said...

for 2009, what if you have a private project that the client just hangs on when you actually scope it and do an AOTDelete()?

index said...
This comment has been removed by the author.
index said...

There is much safer description of how you can get access to all private projects and delete them:
http://daxonline.org/1522-getting-access-to-private-projects.html