05-22-2017 01:12 PM
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.
05-22-2017 02:28 PM
Hi,
after doc.content=... add the line
doc.save();
Then you should see your doc in userhome.
Explore our Alfresco products with the links below. Use labels to filter content by product module.