Skip to main content

Notifications

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.

  • Raj101 Profile Picture
    5 on at
    RE: Batchjob for TFS synchronisation.

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

  • Martin Dráb Profile Picture
    232,866 Most Valuable Professional on at
    RE: Batchjob for TFS synchronisation.

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

  • Verified answer
    Martin Dráb Profile Picture
    232,866 Most Valuable Professional on at
    RE: Batchjob for TFS synchronisation.

    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.

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 294,118 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,866 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Product updates

Dynamics 365 release plans