cancel
Showing results for 
Search instead for 
Did you mean: 

problem with webscript to update a document

geveritt
Champ in-the-making
Champ in-the-making
I am new to Alfresco and I am using Alfresco version 2.9.0B.  I have made some changes to the google gadgets

update.post.js as below…  The problem is when it attempts to execute the statement

document.properties.content.write(content);

I get an error org.mozilla.javascript.EvaluatorException: Can't find method org.alfresco.repo.jscript.ScriptNode$ScriptContentData.write(string) (AlfrescoScript#19)
which is the line with the …content.write(content).  The node contains HTML text and the content variable contains HTML text.

The search.findNode seems to work and setting the encoding seems to work.  If I comment out the …content.write(content) the document.save() seems to work.

I'm not sure how to fix this problem.  Any help would be appreciated.

Thanks
Glenn E.


//Code below
var content = args["content"];
var id = args["id"];


// ensure mandatory file attributes have been located
if (content == null)
{
   status.code = 400;
   status.message = "Uploaded file cannot be located in request.";
   status.redirect = true;
}
else
{
   // update document with uploaded content
   var document = search.findNode("workspace://SpacesStore/" + id);
   if (document != null)
   {
      document.properties.content.encoding = "UTF-8";
      document.properties.content.write(content);
      document.save();
     
      // setup model for response template
      model.document = document;
   }
   else
   {
      status.code = 400;
      status.message = "Error: File for update does not exist";
      status.redirect = true;
   }
}
4 REPLIES 4

tommorris
Champ in-the-making
Champ in-the-making
I'm not certain, but shouldn't the line:
  document.properties.content.write(content);
be more like:
  document.properties["cm:content"] = content;

Tom
http://www.ixxus.com

davidc
Star Contributor
Star Contributor
I believe the following also works…

document.content = content;

This is suitable for non-binary only.  The write method allows binary data to be written, but you need get the source content from another document in the repository or from a posted form field.

geveritt
Champ in-the-making
Champ in-the-making
Thanks for the reply you are both correct I was using the wrong method.  Webscripts are very cool!
Smiley Happy

sanket
Champ on-the-rise
Champ on-the-rise
Thanks guise.
This post was really helpful.