cancel
Showing results for 
Search instead for 
Did you mean: 

nodeService setProperties on space

rascio
Champ in-the-making
Champ in-the-making
Hi at all,
i've got a problem with the nodeService. I've made a webscript to set some properties like cm:description and cm:title to a node in Alfresco…
when i call this webscript on a content that's all right…but when i try to change this properties on a space the code don't throw exceptions but alfresco don't change this property…i'm using the Alfresco Enterprise 3.2. Is this a known bug?
3 REPLIES 3

mrogers
Star Contributor
Star Contributor
No.   Its not a known bug.   And I could go into Alfresco Explorer and demonstrate that setting properties through the node service works.

Is it possible that an error later in your script causes the transaction to roll back?   That's the most likely explanation for your properties failing to update.

billmce
Champ in-the-making
Champ in-the-making
For what it's worth … I'm also searching the forums to solve my problems setting 'title' and 'description'.

I've been working with a modified version of the sample upload script http://wiki.alfresco.com/wiki/Web_Scripts_Examples#Upload_Form

The script works fine but the title and description are not being set.
For completeness … my controller code

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

for each (field in formdata.fields) {
   if (field.name == "name") {
      model.name = field.value;
   }
   if (field.name == "file" && field.isFile) {
      content = field.content;
      mimetype = field.mimetype;
   }
   if (field.name == "filename") {
      filename = field.value;
   }
   if (field.name == "title")
     {
          title = field.value;
     }
   if (field.name == "desc")
     {
          description = field.value;
     }
   if (field.name == "uploadDirectory") {
     uploadDirectory = field.value;
     }
      
}
//Place the file in the appropriate folder.
//If not set it goes into 'company home'
if (uploadDirectory !== null) {
   
        //now determine if this folder exists … create it if required.
   myArray = uploadDirectory.split("/");
   var BuildPath="";
   var DoneFolder = null;
   var testFolder = "";
   var startFolder;
   for (x in myArray)

   {
     //does this folder exist?
     if (DoneFolder === null)
     {
      startFolder = companyhome;
     }
    else
     {
        startFolder = companyhome.childByNamePath(DoneFolder);
     }
      
     if(DoneFolder === null){
        testFolder = myArray[x];
     }
     else
     {
        testFolder = DoneFolder + "/" + myArray[x];
     }   
     testNode = companyhome.childByNamePath(testFolder);
          if (testNode === null){
        //this folder doesn't exist create it.
        var myfolder = startFolder.createFolder(myArray[x]);
     }    
     if (DoneFolder === null){
        DoneFolder = myArray[x];
     }
     else
     {
        DoneFolder = DoneFolder + "/" + myArray[x];
     }
   }
   var targetFolder = companyhome.childByNamePath(uploadDirectory);   
}
else
{
   var targetFolder = companyhome;
}

// handle overwriting file if required
// handle assigning aspects

// Does the file already exist?
var existingFile = companyhome.childByNamePath(uploadDirectory + "/" + filename);
if (existingFile === null){
   //this is a new file.
   var newDoc = targetFolder.createFile(filename);
   newDoc.properties.content.write(content);
   newDoc.properties.content.mimetype = mimetype;
   newDoc.properties.content.encoding = "UTF-8";
   newDoc.properties.title = title;
   newDoc.properties.description = description;
   // Make file versionable ..  autoversion & create initial version
   var props = new Array(2);
   props["cm:autoVersion"] = true;
   props["cm:initialVersion"] = true;
   newDoc.addAspect("cm:versionable", props);
   // now save it
   newDoc.save();
}
else
{
   //this is an existing file.
   //overwrite it.
   //but first make sure old version preserved.
   if (!existingFile.hasAspect("cm:versionable")){
      //Turn on versioning and save original
      var props = new Array(2);
      props["cm:autoVersion"] = true;
      props["cm:initialVersion"] = true;
      existingFile.addAspect("cm:versionable", props);
      existingFile.save();
   }

   existingFile.properties.content.write(content);
   model.document = existingFile;
   existingFile.properties.content.guessMimetype(filename);
   existingFile.properties.content.encoding = "UTF-8";
   existingFile.save();
}

Why aren't the title and description being set?
Thanks in advance.

billmce
Champ in-the-making
Champ in-the-making
Found my problem … hopefully posting this will help others in the future.
I changed the code above to use:

      props["cm:title"] = title;
      props["cm:description"] = description

to assign title and description

hope that helps