Publish resource file via JSCode
Hello,
I'm trying to create and publish resource files dynamically by JS code but I'm not being able to publish them after creating.
My code is as follows:
var file = new File("F:\\Attachments\\current\\attach1.pdf");
if(!file.exists)
logError ("File '" + file.fullName + "' does not exist.");
var extension = /[^.]+$/.exec(file.name);
var md5 = digestStrMd5(file.name);
if (!file.copyTo("E:\\Adobe\\Campaign\\var\\campaign_tst\\upload\\" + md5 + "." + extension))
logError ("File '" + file.fullName + "' was not copied");
var xmlString = '<fileRes alt="" codepage="0" height="0" name="'+md5+'" nature="" publish="1" storageType="5" useMd5AsFilename="1" userContentType="0" version="" width="0" xtkschema="xtk:fileRes"/>'
var fileRes = xtk.fileRes.create( new XML(xmlString));
fileRes.contentType="application/pdf";
fileRes.label = "Attachment 1"
fileRes.md5 = md5;
fileRes.fileName = md5;
fileRes.originalName = md5+".pdf";
fileRes.save();
fileRes.PublishIfNeeded();
After this code, the files are always with the state publishing is needed:

Are there any suggestions on how can I publish this attachments via code?
Even if I have to load them in a separate JS.
Thanks in advance