Change version manually?

cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
patrik
Active Member

Change version manually?

Hi! It seems to be hard to change the version number by executing a script. Is there things i need to do before? My code is the following:

var refName = document.properties["cm:name"];
var refFile = companyhome.childByNamePath(refName);
document.properties.autoVersion=false;
document.properties.versionLabel=refFile.properties.versionLabel;
document.save;

var logFile = space.childByNamePath("log.txt");
if (logFile==null)
{
   var logFile = space.createFile("log.txt");
}
if (logFile!=null)
{
   logFile.content+= "\n\r" + " Version refFile" + refFile.properties.versionLabel + " Version document " + document.properties.versionLabel;
}

What the script is supposed to do is to take the version from a file under Company Home which has the same filename as the file that is referred to as "document". The logfile gives this output:

              Version refFile1.1 ref Version document 1.1

Which indicates that the version is updated to 1.1 but in the browser it's still 1.0. I have tried to make to following change in contentModel.xml:
      <aspect name="cm:versionable">
         <title>Versionable</title>
         <properties>
            <property name="cm:versionLabel">
               <title>Version Label</title>
               <type>d:text</type>
               <protected>false</protected>
            </property>

But without any success.

Hints?
2 Replies
slothrop
Member II

Re: Change version manually?

You could try to remove the aspect, change it and readd it.  This has worked for me with custom aspects when just reassigning a value didn't work:

var oldVersion = document.properties[cm:versionLabel];
/*increment however you see fit*/
document.removeAspect("cm:versionable");
var props = new Array(1);
props["cm:versionLable"] = newVersion;
document.addAspect("cm:versionable", props);

No guarantees, though.
patrik
Active Member

Re: Change version manually?

Thanks for you reply! But it didn't work even though i tried your suggestion. Fortunately, however, i managed to find out what i needed to do. After i set
document.properties.initialVersion=false;
it worked. It looks like the version property becomes static and not automatically set. It even seems impossible to check out the document afterwards but luckily i don't need that in this case.