cancel
Showing results for 
Search instead for 
Did you mean: 

WebScript for update file content with a .doc converted file

weggyboy
Champ in-the-making
Champ in-the-making
hi, all!
I´m trying to update the content of an existing HTML file in Alfresco with a new converted file content.
The new content should come from a .doc->HTML  file convertion. All this should happen with a webScript.

I cannot just delete the current file, because it is being referenced outside alfresco. So just the content has to be changed, not the file "last:transformed.html".

this is what I´m using, but it doesn´t work.

// check if it is any .doc file in the folder already
// if there is one, delete it
var nodes = space.childrenByXPath("*[@cm:name='.doc']");
for (var i=0; i < nodes.length; i++)
{
   nodes[i].remove();
}

// check if it is a "last_transformed.html" file in the folder already
var lastfile = space.childByNamePath("last_transformed.html");

if (lastfile != null) {
   transformed = document.transformDocument("text/html", space);
   lastfile.content = transformed.content;
   lastfile.save();
   transformed.remove();
}

Does anybody have any idea, why it doesn´t work? what am I doing wrong?
3 REPLIES 3

weggyboy
Champ in-the-making
Champ in-the-making
problem was solved without childrenByXPath…

thanks anyway.

dooley
Champ in-the-making
Champ in-the-making
I tried to duplicate your code; however I am thrown error that says space is not defined.  I thought space was a default root object, do I have to declare this at the beginning of my code??

davidc
Star Contributor
Star Contributor
Within a Web Script context, the space root object is not available in the javascript and freemarker apis.

It's the responsibility of the script to locate any repository objects (based on arguments etc).  companyhome etc are available.