AnsweredAssumed Answered

checkin with no errors, but the file remains the same

Question asked by vale_arna84 on Jun 7, 2010
Latest reply on Jun 8, 2010 by vale_arna84
Hello,

I'm uploading a pdf file to alfresco through a multipart form and I want to checkout/checkin an existing node. The pure upload web script worked fine and I've decided to modify it according to a sample web script I've found on the wiki to checkout/checkin the original file.
The script works fine (the debugger doesn't report exceptions), but the original copy doesn't change. I've also watched some variables to better understand the problem, but I can't understand where I'm wrong. All seems fine, the working copy gets the right attributes, but I can't see it on the Alfresco repo.
The variable workingCopy.url is:

/d/d/workspace/SpacesStore/2e0b110a-0ebd-4003-86ad-00b85787cb2a/new%20(Working%20Copy).pdf

But if I check with the browser after the checkout I receive "file not found" (obviously completing the url).

At the end of the script the original file is not cm:versionable even if the script sets this property without errors on the working copy and then does the checkin as well.

Can this be a permissions problem? the user which is calling the script isn't the owner of the file, but using Alfresco web client I've added the group EVERYONE with roles Collaborator to the file content users.
 
This is my javascript code:

var filename = null;
var content = null;
var title = "";
var description = "";
var taskId = "";

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


  // create document in company home for uploaded file
  updateNodeRef = workflow.getTask(taskId).getPackageResources()[0].nodeRef;
  var workingCopy = search.findNode(updateNodeRef);
  if (workingCopy.isLocked)
  {
     // We cannot update a locked document
     status.code = 404;
     status.message = "Cannot update locked document '" + updateNodeRef + "', supply a reference to its working copy instead.";
     status.redirect = true;
  }
  if (!workingCopy.hasAspect("cm:workingcopy"))
  {
     // Ensure the original file is versionable - may have been uploaded via different route
     if (!workingCopy.hasAspect("cm:versionable"))
     {
        // Ensure the file is versionable - but do not autoversion or create initial version yet
        var props = new Array(2);
        props["cm:autoVersion"] = false;
        props["cm:initialVersion"] = false;
        workingCopy.addAspect("cm:versionable", props);
     }
     if (workingCopy.versionHistory == null)
     {
        // Create the first version manually so we have 1.0 before checkout
        workingCopy.createVersion("", true);
     }
     // It's not a working copy, do a check out to get the actual working copy
     workingCopy = workingCopy.checkout();
  }
  // Update the working copy content
  workingCopy.properties.content.write(content);
  // Reset working copy mimetype and encoding
  workingCopy.properties.content.guessMimetype(filename);
  workingCopy.properties.content.encoding = "UTF-8";
  // check it in again, with supplied version history note
  workingCopy = workingCopy.checkin(description);
  workingCopy.save();
  model.document = workingCopy;

Thanks for the help.

Valerio

Outcomes