cancel
Showing results for 
Search instead for 
Did you mean: 

Error creating file through webscript

pat9rv3sousa
Champ on-the-rise
Champ on-the-rise

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 1

mehe
Elite Collaborator
Elite Collaborator

Hi,

after doc.content=...     add the line

doc.save();

Then you should see your doc in userhome.