blog for Dynamics Axapta

Posts tagged ‘ax 2012 export job’

Export your AOT Custom Objects Automatically

Hi,

Here I have posted a job to export all our newly created projects / jobs / any AOT objects as XPO automatically.

static void VAS_ExportXPO(Args _args)
{
#AOT

FileIoPermission perm;
ProjectListNode projectListNode;
ProjectNode projectTreeNode;
TreeNode treeNode, jobTreeNode;
TreeNodeIterator iterator, jobIterator;
str projName;
str exportProjName = ‘VAS_’;
str jobName;
str exportJobName = ‘VAS_’;
int noOfProjects;
int noOfJobs;
str folderpathProj, folderpathJobs;

#define.ExportMode(“w”)

;
folderpathProj = strfmt(@’C:\Vasanth Arivali\XPO Backup\%1\SharedProject’, date2str(today(), 321, 2, 3, 2, 3, 4));
folderpathJobs = strfmt(@’C:\Vasanth Arivali\XPO Backup\%1\Jobs’, date2str(today(), 321, 2, 3, 2, 3, 4));
WINAPI::createDirectoryPath(folderpathProj);
WINAPI::createDirectoryPath(folderpathJobs);

perm = new FileIoPermission(folderpathProj, #ExportMode);
if (perm == null)
{
return;
}
perm.assert();

projectListNode = SysTreeNode::getSharedProject();
iterator = projectListNode.AOTiterator();

treeNode = iterator.next();
while (treeNode)
{
projName = treeNode.AOTname();
if ( exportProjName == substr(projName, 1, 8))
{
// BP deviation documented.
treeNode.treeNodeExport(folderpathProj + ‘\\SharedProject_’ + projName + “.xpo”);
noOfProjects++;
}
treeNode = iterator.next();

}

jobIterator = TreeNode::findNode(@’\Jobs’).AOTiterator();
jobTreeNode = jobIterator.next();
while (jobTreeNode)
{
jobName = jobTreeNode.AOTname();
if ( exportJobName == substr(jobName, 1, 8))
{
// BP deviation documented.
jobTreeNode.treeNodeExport(folderpathJobs + ‘\\Job_’ + jobName + “.xpo”);
noOfJobs++;
}
jobTreeNode = jobIterator.next();

}

CodeAccessPermission::revertAssert();

if (noOfProjects > 0)
info(strfmt(‘%1 Projects exported sucessfully’, noOfProjects));
if (noOfJobs > 0)
info(strfmt(‘%1 Jobs exported sucessfully’, noOfJobs));
}

Hope this will help you guys.

// Vasanth Arivali