Forum Discussion
remco_van_oosterhout
8 years agoIdeator III
Well, we're not just talking about the File item but also the physical file that resides in the vault. You don't want people working in the original file.
This is the code I have so far:
Item thisItem = this;
Innovator inn = thisItem.getInnovator();
string templateId = thisItem.getProperty("from_template", "");
//If item is not based on a template skip this entire method
if (templateId.Equals("")){
return thisItem;
}
//Get the relationship item pointing to the template file
string aml = "<AML><Item action='get' type='Document File'><source_id>" + templateId + "</source_id></Item></AML>";
Item officeFileItem = inn.applyAML(aml);
if(officeFileItem.isError()){
return thisItem;
}
//Get the file ID
string fileId = officeFileItem.getProperty("related_id");
Item templateFile = inn.getItemById("File", fileId);
//Prepare a name for the file
string fileName = thisItem.getProperty("keyed_name");
Item myFile = inn.newItem("File","copyAsNew");
myFile.setAttribute("id", fileId);
myFile.setAttribute("useInputProperties", "1");
myFile.setProperty("filename", fileName);
myFile = myFile.apply();
//Above didn't result into anything, so I added the following code to manually relate the File item to the Document item
Item myFileRel = inn.newItem("Document File","add");
myFileRel.setRelatedItem(myFile);
thisItem.addRelationship(myFileRel);
//Still no visible result
return thisItem;
I've managed to determine that the related file item is found so the problem specifically resides in the creation/copying of the new file and File item.