Exporting Projects From AX

After my hard drive crash, I decided that I should really create a way to automatically back up all the code for all of my active projects. So, I’ve added an “exportAllProjects()” method to my “startup projects” class. This method takes my list of active projects, iterates through them, and exports each one to a standard XPO file, in a sub-folder off the My Documents folder.

I’ve created a menu item for this, and attached it to the Development Tools menu. So, now I can backup all the objects in all of my active projects in one fell swoop. It would nice to be able to do this automatically, but I’m not sure I want to start messing around with doing this as a scheduled job just yet.

/andyhuey/5470950
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
public void exportAllProjects()
{
    // get the project list, and export all projects.
    Array projects;
    int i;
    ProjectNode sharedProjects, privateProjects, projectNode;
    str myDocsPath, filePath;
 
    #WinAPI
 
    myDocsPath = WinAPI::getFolderPath(#CSIDL_PERSONAL);
    myDocsPath += @"\xpo_backup";
 
    // make sure myDocsPath exists.
    if (!WinAPI::pathExists(myDocsPath))
    {
        WinAPI::createDirectoryPath(myDocsPath);
    }
 
    projects = this.getProjectList();
 
    sharedProjects = Infolog.projectRootNode().AOTfindChild('Shared');
    if (!sharedProjects)
        throw error("Error: cannot located shared project node!" );
 
    privateProjects = Infolog.projectRootNode().AOTfindChild('Private');
    if (!privateProjects)
        throw error("Error: cannot located private project node!" );
 
    for (i= 1; i <= projects.lastIndex(); i++)
    {
        // skip any line starting with a semi-colon
        if (subStr (projects.value(i), 1, 1) == ";" )
            continue;
 
        projectNode = sharedProjects.AOTfindChild(projects.value(i));
        if (!ProjectNode)
            projectNode = privateProjects.AOTfindChild(projects.value(i));
 
        if (projectNode)
        {
            filePath = myDocsPath + @"\" + projects.value(i) + ".xpo" ;
            projectNode.treeNodeExport(filePath);
        }
        else
            warning(strFmt("Project %1 cannot be found." , projects.value(i)));
    }
}

Leave a Reply