<?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>Renaming File via Document Relationship - A journey</title><link>https://www.aras.com/community/f/development/36665/renaming-file-via-document-relationship---a-journey</link><description>Hi Community, 
 
 Need some help here. I have a method to rename a file related to a document. The idea is that upon check-in the filename will update to the Doc Number + Name + Rev + Generation 
 
 It works for the most part but there are 4 errors depending</description><dc:language>ja-JP</dc:language><generator>Telligent Community 12</generator><item><title>RE: Renaming File via Document Relationship - A journey</title><link>https://www.aras.com/community/thread/7151?ContentTypeID=1</link><pubDate>Fri, 23 Jul 2021 18:24:35 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:58312c33-fa65-4464-8e83-27fe0b55b2be</guid><dc:creator>Morgan</dc:creator><description>&lt;p&gt;I figured it out. Replaced this with item and all is well with onBeforeUnlock.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Renaming File via Document Relationship - A journey</title><link>https://www.aras.com/community/thread/7066?ContentTypeID=1</link><pubDate>Thu, 08 Jul 2021 13:52:18 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:9bd48fbb-5cee-4eda-859f-7d49c7dcd4c0</guid><dc:creator>Morgan</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I only want to use one event type if possible. We are using the connector, however I attempted each type due to the fact that none of them were able to complete the task without issue. The closest and most ideal would be OnAfterUpdate however the office connector throws the error.&lt;/p&gt;
&lt;p&gt;Here is the code:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="csharp"&gt;Innovator inn = this.getInnovator();
string sourceId = this.getID();

String relationshipName;
//,souceProperty, sourceContentLocation;

//Item queryFile, 
Item item, files, file;

//filetype or doc validation if reuqired
if (true) {
    relationshipName = &amp;quot;Document File&amp;quot;;

    item = this.newItem(&amp;quot;Document&amp;quot;, &amp;quot;get&amp;quot;);
    item.setProperty(&amp;quot;id&amp;quot;, sourceId);
    Item isRelationship = this.newItem(relationshipName, &amp;quot;get&amp;quot;);
    item.addRelationship(isRelationship);
    item = item.apply();

//get all Documet Files 
    files = item.getRelationships(relationshipName);
    
    //To iterate through attached files
    for (int i = 0; i &amp;lt; files.getItemCount(); i++) {
        file = files.getItemByIndex(i);
        file = file.getRelatedItem();

//string to be added into filename
        string stringToRenameFile = this.getProperty(&amp;quot;item_number&amp;quot;) + &amp;quot; &amp;quot;+ this.getProperty(&amp;quot;name&amp;quot;) + &amp;quot; &amp;quot; + this.getProperty(&amp;quot;major_rev&amp;quot;) + &amp;quot;v&amp;quot; + this.getProperty(&amp;quot;generation&amp;quot;);

        string fileId = file.getID();
        string fname = file.getProperty(&amp;quot;filename&amp;quot;);

        string[] array = fname.Split(&amp;#39;.&amp;#39;);
        fname = string.Empty;
        if (array.Length == 1) {
            fname = stringToRenameFile + array[1];
        } else {
            for (int j = 0; j &amp;lt; array.Length; j++) {
                fname += array[j];
                if (j == array.Length - 2)
                if (j != array.Length - 1)
                {
                    fname = stringToRenameFile;
            fname = stringToRenameFile + &amp;quot;.&amp;quot;;
                }
                    }
        }
        file = this.newItem(&amp;quot;File&amp;quot;);
        file.setAttribute(&amp;quot;action&amp;quot;, &amp;quot;RenameFile&amp;quot;);
        file.setID(fileId);
        file.setProperty(&amp;quot;filename&amp;quot;, fname);

        // to get root user permission via identity
        Aras.Server.Security.Identity identity = Aras.Server.Security.Identity.GetByName(&amp;quot;Super User&amp;quot;);
        bool permsWasSet = Aras.Server.Security.Permissions.GrantIdentity(identity);

        file = file.apply();

        //acquired root user permission should be revoked
        if (permsWasSet)
            Aras.Server.Security.Permissions.RevokeIdentity(identity);
    }
}
return this;&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Renaming File via Document Relationship - A journey</title><link>https://www.aras.com/community/thread/7058?ContentTypeID=1</link><pubDate>Thu, 08 Jul 2021 07:28:58 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:9f5c125f-1e74-4c25-81c9-0948829532ab</guid><dc:creator>AngelaIp</dc:creator><description>&lt;p&gt;This one requires some background information first.&lt;/p&gt;
&lt;p&gt;1. Do you use the Aras Office Connector?&lt;/p&gt;
&lt;p&gt;2. Why do you want to use all available Method events types (onBeforeLock??)? Do you really want to rename your document every time &amp;quot;something&amp;quot; happens?&lt;/p&gt;
&lt;p&gt;3. onAfterAdd/Update/Version should do the job. Which code do you use for updating the item?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>