Error creating file through webscript

cancel
Showing results for 
Search instead for 
Did you mean: 
pat9rv3sousa
Active Member

Error creating file through webscript

I'm trying to create a file if it doesn't exists or modified it if it exists.

I created a webscript:

> createfile.get.js

function main()

{
var doc = userhome.childByNamePath('answers.txt');
if (!doc)
{
doc = userhome.createFile("answers.txt");
doc.addAspect("cm:versionable");
doc.content = 'Questionnaire';

var trans1 = doc.transformDocument('application/pdf');
}
else {
var workingCopy = doc.checkout();
workingCopy.content = 'Questionnaire modified';

// check it in
doc = workingCopy.checkin();
}
model.doc=doc;


}

main();


However, if I don't have the file in my home, this doesn't create the new file. If I create manually the file "answers.txt" in Alfresco, it modifies the content. Any reason for this?

In catalina.out or in the debugger in the browser, I don't get any information of any error.

Thanks.

1 Reply
mehe
Senior Member II

Re: Error creating file through webscript

Hi,

after doc.content=...     add the line

doc.save();

Then you should see your doc in userhome.