web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Batchjob for TFS synchronisation.

(0) ShareShare
ReportReport
Posted on by 5

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.

I have the same question (0)
  • Verified answer
    Martin Dráb Profile Picture
    237,801 Most Valuable Professional on at

    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.

  • Martin Dráb Profile Picture
    237,801 Most Valuable Professional on at

    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");
    }

  • Raj101 Profile Picture
    5 on at

    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");
    }
    }
    }

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 660 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 549 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 307 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans