cancel
Showing results for 
Search instead for 
Did you mean: 

Access Node History Content

alfsender
Champ in-the-making
Champ in-the-making
Hi All,

I am writing a web-script where I need to copy content from node history and make new version from it.

For example I have node which has version history as 1, 1.1, 1.2, 2.0, 2.1. Now I want to create new version 3.0 using content of version 1.0. I tried using versionHistory but after update when i see content in share it shows as undefined. Below is the code snippet which I am using, please provide your valuable suggestion.

   
var resultNode = search.findNode("workspace://SpacesStore/" + "6e5dabc3-fe8a-4c5e-b470-5c2484720e45");
    var versionHistory = resultNode.versionHistory;
    var majorVersion = 1.0;
    var sourceVersion;
    for (i = 0; i < versionHistory.length; i++) {
        var version = versionHistory;
        if (version.label == majorVersion) {
            sourceVersion = version;
            break;
        }
    }
    var historyNode = search.findNode(sourceVersion.nodeRef);
    var workingCopy = resultNode.checkout();
    workingCopy.content = sourceVersion.content;
    workingCopy.checkin("Major Version", true);



Let me know if you want me to add more information here.

1 REPLY 1

muralidharand
Star Contributor
Star Contributor
Hi,
Please take a look at the code from the below link.
/**
     * Revert this Node to the specified version. Note this is not a deep revert of
     * associations.
     * This node must have the cm:versionable aspect. It will be checked out if required
     * but will be checked in after the call.
     *
     * @param versionLabel to revert from
     *
     * @return the original Node that was checked out if reverted, {@code null} otherwise
     *         (if the version does not exist).
     */
    public ScriptNode revert(String history, boolean majorVersion, String versionLabel)
    {
        return revert(history, majorVersion, versionLabel, false);
    }
https://svn.alfresco.com/repos/alfresco-open-mirror/alfresco/COMMUNITYTAGS/5.1.b/root/projects/repos...

Hope you will get some idea.