Announcements
Can we create a batch job for TFS synchronisation in AX 2012 to run every night after working hours? If yes, How do we achieve it.
Thanks for reply!
I created RunBaseBatch class with the above code and ran, Batch stays in Executing status always. I suspect it is because all version control synchronisation classes are set to run in client.
and as you said i tried startup cmd to run from powershell, It worked. So i can now set a task scheduler for it instead of batchjob.
Thanks again for the help :).
I used below code with some modification.
SysVersionControlSynchronization SysVersionControlSynchronization;
SysVersionControlSyncParameters syncParm;
SysVersionControllable controllable;
SysVersionControlSystemFileBased sysVersionControlSystem;
SysVersionControlTmpChange processedSyncElements;
SysVersionControlSynchronizeBatchNum batchNum;
Filename filename;
SysVersionControlSynchronizeCommand command;
boolean noInfo = false;
Set folderSetSelected;
Set folderSet;
SetEnumerator folderSetEnum;
Map resultMap;
MapEnumerator mapEnum;
boolean isVCSDefFile = true;
SysTreeNodeContainer contControllable;
RecordInsertList syncEntries;
SysVersionControlFilebasedBackEnd backend;
SysVersionControlRepositoryFolder folder;
int i;
container folderCon = ["modelNameToSync"]; // model names to be syn
;
SysVersionControlSynchronization = SysVersionControlSynchronization::construct();
if (!SysVersionControlParameters::isVCSEnabled())
{
throw error("@SYS135983" + ' ' + strFmt("@SYS120745", "@SYS85914"), '', SysInfoAction_Formrun::newFormname(formStr(SysVersionControlParametersDev)));
}
if (versioncontrol &&
versioncontrol.parmSysVersionControlSystem() &&
!versioncontrol.parmSysVersionControlSystem().supportSynchronization())
{
throw error("@SYS112528");
}
// one batchNum for the whole syn
batchNum = SysVersionControlSynchronizeLog::nextBatchNum();
// When client synchronizes the VCSDef must be synchronized as well for getting latest
// updates of models.
versioncontrol.init();
// Synchronize files for each folder
for (i = 1; i<= conLen(folderCon); i++)
{
sysVersionControlSystem = versioncontrol.parmSysVersionControlSystem();
if (sysVersionControlSystem)
{
// folder in the TFS client side
folder = SysVersionControlParameters::find().RepositoryFolder + "\\" + SysVersionControlParameters::find().AppRoot + "\\" + conPeek(folderCon,i);
syncParm = SysVersionControlSyncParameters::construct();
syncParm.parmSilent(false);
syncParm.parmForce(true); // To do , change here if "force" is required
syncParm.parmDeleteLocalObjects(false);
syncParm.parmSyncAll(true);
// Evaluate if controllable is special for setting additional parameters.
if (controllable && isVCSDefFile)
{
syncParm.parmSilent(true);
}
if (syncParm.parmSyncAll())
{
folderSet = new Set(Types::String);
folderSet.add(folder);
backend = sysVersionControlSystem.parmBackend();
resultMap = backend.folderSetSynchronize(folderSet, syncParm);
}
if (resultMap) //Sync succeeded
{
mapEnum = resultMap.getEnumerator();
syncEntries = new RecordInsertList(tableNum(SysVersionControlSynchronizeLog));
while (mapEnum.moveNext())
{
filename = mapEnum.currentKey();
command = mapEnum.currentValue();
controllable = SysVersionControlTmpItem::newControllable(sysVersionControlSystem.filename2ItemPath(filename), filename);
syncEntries.add(SysVersionControlSynchronizeLog::initLogEntry(
filename,
controllable,
command,
batchNum,
folder));
SysVersionControlTmpItem::releaseControllable(controllable);
}
syncEntries.insertDatabase();
if (resultMap.elements() && !syncParm.parmSkipImport())
{
SysVersionControlSynchronizeLog::processBatchNum(batchNum);
}
}
else
{
throw error("@SYS85688");
}
}
}
You may also want some validations before running the sync:
if (!SysVersionControlParameters::isVCSEnabled()) { throw error("@SYS135983"); } if ( versioncontrol && versioncontrol.parmSysVersionControlSystem() && !versioncontrol.parmSysVersionControlSystem().supportSynchronization()) { throw error("@SYS112528"); }
I used to use code like this:
SysVersionControlUserInterfaceSilent uiProvider; Set folders = new Set(Types::String); folders.add(... folder path ...); //Don't show any user dialogs uiProvider = SysVersionControlUserInterfaceSilent::construct(); //Set folder to synchronize with uiProvider.parmPromptForFolder(folders); versioncontrol.parmUserInterfaceProvider(uiProvider); versioncontrol.init(); versioncontrol.getLatestVersion(TreeNode::rootNode());
But I used in a client startup command, not in a batch.
I don't remember the solution in AX 2012 very well, but I suspect that there are objects with dependencies on client and therefore it can't run in batch. Try it and you'll see if it's the case.
André Arnaud de Cal...
294,118
Super User 2025 Season 1
Martin Dráb
232,866
Most Valuable Professional
nmaenpaa
101,158
Moderator