cancel
Showing results for 
Search instead for 
Did you mean: 

Webscript and versioning

zafarale
Champ in-the-making
Champ in-the-making
I have a put webscript which recieved form
Find content with provided id
Updates content
File name
Tags
And saves it by calling node.save

But alfresco is throwing error

org.alfresco.service.cmr.version.VersionServiceException: 04120024 The current version label of the node does not exist in the version history."


Most annoyingly it does that in 70% of cases.
This file resides in space which has versioning aspect enabled

here is the script


var paramsArray = new String(url.extension).split("/")

var homeId = paramsArray[0];
var fileId = paramsArray[2];

var filename = null;
var content = null;
var tagsList;
var title;
var description;

for each (field in formdata.fields) {
   if (field.name == "title") {
      title = field.value;
   }
   else if (field.name == "description") {
      description = field.value;
   }
     else if (field.name == "tagsList") {
       tagsList = field.value;
     }
   
   if (field.name == "file" && field.isFile) {
      filename = field.filename;
      content = field.content;
   }
}


if (homeId.length == 0 || fileId.length == 0) {
   status.code = 400;
   status.message = "A required parameter has not been provided.";
   status.redirect = true;
} else if (filename == undefined || content == undefined) {
      // ensure mandatory file attributes have been located
        status.code = 400;
        status.message = "Uploaded file cannot be located in request.";
        status.redirect = true;
} else {
   var fileExists = false;   
   var file;
   var homesFolder = companyhome.childByNamePath("FOLDER");
   var targetFolder = homesFolder.childByNamePath(homeId);
   var duplicateFileName = false;
   if (targetFolder != undefined) {
      var children = targetFolder.getChildren();
      for (var i = 0; i < children.length; i++) {
         if (new String(children.getId()).valueOf() == new String(fileId).valueOf()) {
            fileExists = true;
            file = children;
         } else if (new String(children.getName()).valueOf() == new String(filename).valueOf()) {
            //File name already belongs to another file.
            duplicateFileName = true;
         }
      }
   }


   if (fileExists && !duplicateFileName) {
      
      if (title != undefined) {
         file.properties.title = title;
      }
      if (description != undefined) {
         file.properties.description = description;
      }

      var fileTags = file.getTags();
      for (var i = 0; i < fileTags.length; i++) {
         if (new String(fileTags).substring(0,4) != "api.") {
            file.removeTag(fileTags);
         }
      }
         file.addTag(tagsList);

      if (filename != undefined && !new String(filename).valueOf() == "") {
         file.properties.name = filename;
         file.properties.content.write(content);
         file.properties.content.setEncoding("UTF-8");
         file.properties.content.guessMimetype(filename);
      }

      file.save();
      model.upload = file;
      model.homeid = homeId;

   } else if (!fileExists) {
      status.code = 400;
      status.message = "File specified (" + fileId + ") does not exist for Id: " + homeId;
      status.redirect = true;
   } else {
      status.code = 400;
      status.message = "A file with this name already exists: " + filename;
      status.redirect = true;
   }

2 REPLIES 2

kaynezhang
World-Class Innovator
World-Class Innovator
It seems the code your paste did not have any  version operations 
Are you sure VersionServiceException  is thrown by above code?                                                                                                                                                                    

angelborroy
Community Manager Community Manager
Community Manager
It seems it's versioning on properties updates. Take a look at http://forums.alfresco.com/forum/end-user-discussions/alfresco-share/new-version-update-properties-0... in order to disable this behavior.
Hyland Developer Evangelist