<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://www.aras.com/community/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Copying and appending physical files</title><link>https://www.aras.com/community/f/development/3896/copying-and-appending-physical-files</link><description>Another day, another challenge. I&amp;#39;m still working on our Office Connector integration and one of the features I want to present to my user community is the ability to use templates when creating new Document items. In order to do this a user can set the</description><dc:language>ja-JP</dc:language><generator>Telligent Community 12</generator><item><title>RE: Copying and appending physical files</title><link>https://www.aras.com/community/thread/1993?ContentTypeID=1</link><pubDate>Wed, 05 Sep 2018 15:17:25 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:60f7be85-d4ea-46e7-aadf-b79a3e30241a</guid><dc:creator>Eli Donahue</dc:creator><description>Thanks for sharing your solution, Remco!

Eli

&lt;hr /&gt;

Eli Donahue

Aras Labs Software Engineer&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Copying and appending physical files</title><link>https://www.aras.com/community/thread/1992?ContentTypeID=1</link><pubDate>Wed, 05 Sep 2018 07:28:39 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:d3621156-da18-4317-bd47-4bfe6a0dc598</guid><dc:creator>remco.van.oosterhout</dc:creator><description>Happy to report the problem is solved. The method did already copy the file but failed to append it to the Document item, so all I had to do was create that relationship item. I also added a check at the beginning of the code so I don&amp;#39;t accidentally overwrite any existing file. This method is now fired on the onAfterAdd and onAfterUpdate events.

//Description: If the document item is based on a template, copy the base file and append it to the Document item

Item thisItem = this;
Innovator inn = thisItem.getInnovator();
string thisItemId = thisItem.getID();

string templateId = thisItem.getProperty(&amp;quot;from_template&amp;quot;, &amp;quot;&amp;quot;);

//First check if the Document item doesn&amp;#39;t already have an Office file attached
string aml = &amp;quot;&amp;lt;AML&amp;gt;&amp;lt;Item action=&amp;#39;get&amp;#39; type=&amp;#39;Document File&amp;#39;&amp;gt;&amp;lt;source_id&amp;gt;&amp;quot; + thisItemId + &amp;quot;&amp;lt;/source_id&amp;gt;&amp;lt;/Item&amp;gt;&amp;lt;/AML&amp;gt;&amp;quot;;
Item alreadyHasAFile = inn.applyAML(aml);

//If a relationship item was found, skip the rest of the method
if (!alreadyHasAFile.isError()){
return thisItem;
}

//If item is not based on a template skip this entire method
if (templateId.Equals(&amp;quot;&amp;quot;)){
return thisItem;
}

//Get the relationship item pointing to the template file
aml = &amp;quot;&amp;lt;AML&amp;gt;&amp;lt;Item action=&amp;#39;get&amp;#39; type=&amp;#39;Document File&amp;#39;&amp;gt;&amp;lt;source_id&amp;gt;&amp;quot; + templateId + &amp;quot;&amp;lt;/source_id&amp;gt;&amp;lt;/Item&amp;gt;&amp;lt;/AML&amp;gt;&amp;quot;;
Item officeFileItem = inn.applyAML(aml);

if(officeFileItem.isError()){
return thisItem;
}

//Get the file ID
string fileId = officeFileItem.getProperty(&amp;quot;related_id&amp;quot;);
Item templateFile = inn.getItemById(&amp;quot;File&amp;quot;, fileId);

//Recycle the old filename for the new one
string fileName = templateFile.getProperty(&amp;quot;filename&amp;quot;);

//
Item myFile = inn.newItem(&amp;quot;File&amp;quot;,&amp;quot;copyAsNew&amp;quot;);
myFile.setAttribute(&amp;quot;id&amp;quot;, fileId);
myFile.setAttribute(&amp;quot;useInputProperties&amp;quot;, &amp;quot;1&amp;quot;);
myFile.setProperty(&amp;quot;filename&amp;quot;, fileName);
myFile = myFile.apply();

string newFileId = myFile.getID();
aml = &amp;quot;&amp;lt;AML&amp;gt;&amp;lt;Item action=&amp;#39;add&amp;#39; type=&amp;#39;Document File&amp;#39; &amp;gt;&amp;lt;source_id&amp;gt;&amp;quot; + thisItemId + &amp;quot;&amp;lt;/source_id&amp;gt;&amp;lt;related_id&amp;gt;&amp;quot; + newFileId + &amp;quot;&amp;lt;/related_id&amp;gt;&amp;lt;/Item&amp;gt;&amp;lt;/AML&amp;gt;&amp;quot;;

Item newRelItem = inn.applyAML(aml);

return thisItem;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Copying and appending physical files</title><link>https://www.aras.com/community/thread/1991?ContentTypeID=1</link><pubDate>Mon, 03 Sep 2018 01:46:50 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:0b17a7b8-bab7-45ce-8f05-65580f8c578f</guid><dc:creator>remco.van.oosterhout</dc:creator><description>Hi Eli,

We&amp;#39;re using the Aras Office Connector. When creating a new Document item based on a template Document item in Word this functionality works, but when creating a new Document item in Aras and setting the from_template property this does not result in an appended file item on the new Document item.

Could it be a rights issue on the server, or could I have configured something incorrectly?

Remco&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Copying and appending physical files</title><link>https://www.aras.com/community/thread/1990?ContentTypeID=1</link><pubDate>Fri, 31 Aug 2018 16:38:22 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:4cb4ee4e-9273-4a56-8595-ec5933d3ecf8</guid><dc:creator>Eli Donahue</dc:creator><description>Hi remco.van.oosterhout,

Is this a custom office connector you&amp;#39;ve built, or the Aras Office Connector? I believe the Aras Office Connector supports this functionality without custom code.

Eli

&lt;hr /&gt;

Eli Donahue

Aras Labs Software Engineer&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Copying and appending physical files</title><link>https://www.aras.com/community/thread/1989?ContentTypeID=1</link><pubDate>Fri, 24 Aug 2018 02:48:18 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:0973f83e-baa5-42e5-b188-61323e8b214b</guid><dc:creator>remco.van.oosterhout</dc:creator><description>Well, we&amp;#39;re not just talking about the File item but also the physical file that resides in the vault. You don&amp;#39;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(&amp;quot;from_template&amp;quot;, &amp;quot;&amp;quot;);

//If item is not based on a template skip this entire method
if (templateId.Equals(&amp;quot;&amp;quot;)){
return thisItem;
}

//Get the relationship item pointing to the template file
string aml = &amp;quot;&amp;lt;AML&amp;gt;&amp;lt;Item action=&amp;#39;get&amp;#39; type=&amp;#39;Document File&amp;#39;&amp;gt;&amp;lt;source_id&amp;gt;&amp;quot; + templateId + &amp;quot;&amp;lt;/source_id&amp;gt;&amp;lt;/Item&amp;gt;&amp;lt;/AML&amp;gt;&amp;quot;;
Item officeFileItem = inn.applyAML(aml);

if(officeFileItem.isError()){
return thisItem;
}

//Get the file ID
string fileId = officeFileItem.getProperty(&amp;quot;related_id&amp;quot;);
Item templateFile = inn.getItemById(&amp;quot;File&amp;quot;, fileId);

//Prepare a name for the file
string fileName = thisItem.getProperty(&amp;quot;keyed_name&amp;quot;);

Item myFile = inn.newItem(&amp;quot;File&amp;quot;,&amp;quot;copyAsNew&amp;quot;);
myFile.setAttribute(&amp;quot;id&amp;quot;, fileId);
myFile.setAttribute(&amp;quot;useInputProperties&amp;quot;, &amp;quot;1&amp;quot;);
myFile.setProperty(&amp;quot;filename&amp;quot;, fileName);
myFile = myFile.apply();

//Above didn&amp;#39;t result into anything, so I added the following code to manually relate the File item to the Document item
Item myFileRel = inn.newItem(&amp;quot;Document File&amp;quot;,&amp;quot;add&amp;quot;);
myFileRel.setRelatedItem(myFile);
thisItem.addRelationship(myFileRel);

//Still no visible result

return thisItem;

I&amp;#39;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.&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Copying and appending physical files</title><link>https://www.aras.com/community/thread/1988?ContentTypeID=1</link><pubDate>Thu, 23 Aug 2018 08:51:49 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:76c13d36-2d31-4a37-8584-2fb9c993c592</guid><dc:creator>Alexander Herlitz</dc:creator><description>From what I understood you want to retrive File Item from the document template and copy that File Item so you can attach it to the actual Document created from that template? If yes you can copy the file with &amp;quot;copyAsNew&amp;quot; method. The code could look something like that:
&lt;pre&gt;var fileCopy = this.getInnovator().newItem(&amp;quot;File&amp;quot;, &amp;quot;copyAsNew&amp;quot;);
fileCopy.setAttribute(&amp;quot;id&amp;quot;, fileID); // ID of original File Item
fileCopy.setAttribute(&amp;quot;useInputProperties&amp;quot;, &amp;quot;1&amp;quot;);
fileCopy.setProperty(&amp;quot;filename&amp;quot;, fileName); // fileName is the name of your new copied File
fileCopy = fileCopy.apply();&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>