Martin - Monday, February 9, 2009 9:42 AM:
Hello,
I'am looking for way to add a new file to an existing document item, which has already a file attached to it. In this case I want to "overwrite" the existing file (with a new external generated PDF file) without to checkout the file first.
My Idea was to unlock the document item, find the file item attached to it via the document file relationship (i.e. using
mydocumentItem.getItemsByXPath("//Item[@type='File']")) and then simply use the .attachPhysicalFile method to attach the new file and finally lock the document item.
Unfortunaly instead of a new generation of the document i get a new document??
Does anybody know how to generate a new generation of a document, I couldn't find any hint in the programmers handbook.
Any idea welcome
Martin
aknourenko - Friday, February 27, 2009 12:11 PM:
Martin,
I assume that you are using standard Innovator's item type "Document". Here is a sample code that works just fine and creates generation 2 of the original document:
...
private static void _testDocumentFile(Innovator inn)
{
// Create new item Document
Item doc = inn.newItem("Document", "add");
DateTime dt = DateTime.Now;
doc.setProperty("item_number", string.Format("doc{0}{1}{2}", dt.Hour, dt.Minute, dt.Second));
// Create new item "File" and attach physical file to it
Item file = inn.newItem("File", "add");
file.setProperty("filename", "foo.txt");
file.attachPhysicalFile("c:\temp\a.html");
// Create relationship between document and file
Item doc_file = inn.newItem( "Document File", "add" );
doc_file.setRelatedItem( file );
doc.addRelationship(doc_file);
// Submit new document with file to server. This creates generation 1 of the document.
Item added_doc = doc.apply();
if (added_doc.isError())
{
Console.WriteLine("ERROR: failed to create document with file");
return;
}
// Lock the Document item
added_doc = added_doc.lockItem();
if (added_doc.isError())
{
Console.WriteLine("ERROR: failed to lock the document");
return;
}
// Fetch document-file relationship as it's not brought back in response to doc.apply().
doc_file = added_doc.fetchRelationships("Document File").getRelationships("Document File").getItemByIndex(0);
// Set action of "edit" as it does "unlock" after updating the item (action "update" leaves item locked)
doc_file.setAction("edit");
// Lock item "File"
file = doc_file.getRelatedItem();
file = file.lockItem();
if (file.isError())
{
Console.WriteLine("ERROR: failed to lock the file");
return;
}
// Attach another physical file
file.setAction("edit");
file.attachPhysicalFile("c:\temp\b.txt");
// Set action "edit" on the top Document
added_doc.setAction("edit");
// Submit top item with all subtree. This creates generation 2 of the document.
Item updated_doc = added_doc.apply();
if (updated_doc.isError())
{
Console.WriteLine("ERROR: failed to update document");
}
else
{
Console.WriteLine("Updated document generation = {0}", updated_doc.getProperty("generation"));
}
}
tbischel - Monday, July 26, 2010 2:01 PM:
while this revs the document, the file doesn't seem to get updated.
Yoann Maingon - Monday, July 26, 2010 2:39 PM:
Hi,
While creating the new rev, we delete the existing "Document File" relationship and the file created in the rev creation and we then add the new created file. Don't have a JS example, A VB.net example would help?
Not sure its the best way to do it, but it works fine for us.. We use it for our Autocad integration as we need to update two files in one doc for each rev (dwg + dxf)
Yoann Maingon
tbischel - Monday, July 26, 2010 4:54 PM:
So I ended up finding this thread... http://www.aras.comhttp://www.aras.com/Community/forums/p/674/2037.aspx#2037
if you rev the file with an update, it seems to hold the version history with the file ok. The top part for the document revision still works.