<?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>Adding a related item to a null relationship on onAfterAdd Event of the relationship.</title><link>https://www.aras.com/community/f/development/5524/adding-a-related-item-to-a-null-relationship-on-onafteradd-event-of-the-relationship</link><description>Hi, I have a relationship defined between two item types say part and document and the relationship options available on the form are &amp;quot;No related&amp;quot; and &amp;quot;Create Only&amp;quot; I have a scenario such that when &amp;quot;no related&amp;quot; option is selected and I populate the property</description><dc:language>ja-JP</dc:language><generator>Telligent Community 12</generator><item><title>RE: Adding a related item to a null relationship on onAfterAdd Event of the relationship.</title><link>https://www.aras.com/community/thread/2425?ContentTypeID=1</link><pubDate>Thu, 17 Jan 2019 14:54:34 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:d1f7ccf4-b7b6-47ee-8a6c-e1db3b91b37c</guid><dc:creator>Meismart</dc:creator><description>&lt;p&gt;The Method this.setProperty(&amp;quot;related_id&amp;quot;,idOfrelatedItem)&amp;nbsp;is not the problem here,the problem is &amp;#39;this&amp;#39; is the context item returned to the user, not the item to be saved.&lt;/p&gt;
&lt;p&gt;Assuming that &amp;quot;this&amp;quot; is a single item, or you will have to loop for each item,&amp;nbsp;you can&amp;nbsp;use:&lt;/p&gt;
&lt;p&gt;if (this.getProperty(&amp;quot;related_id&amp;quot;,&amp;quot;&amp;quot;) == &amp;quot;&amp;quot;) &lt;br /&gt;{&lt;br /&gt;&amp;nbsp;Item editItem = innovator.newItem(&amp;quot;ItemType&amp;quot;,&amp;quot;get&amp;quot;);&lt;br /&gt;&amp;nbsp;editItem.setProperty(&amp;quot;id&amp;quot;,this.getProperty(&amp;quot;id&amp;quot;,&amp;quot;&amp;quot;));&lt;br /&gt;&amp;nbsp;editItem =editItem.apply();&lt;/p&gt;
&lt;p&gt;&amp;nbsp;if (editItem.getItemcount() == 1)&lt;br /&gt;&amp;nbsp;{&lt;br /&gt;&amp;nbsp; editItem.setAction(&amp;quot;edit&amp;quot;);&lt;br /&gt;&amp;nbsp; editItem.setProperty(&amp;quot;related_id&amp;quot;,idOfrelatedItem);&lt;br /&gt;&amp;nbsp; editItem = editItem .apply()&lt;br /&gt;&amp;nbsp;}&lt;br /&gt;}&lt;/p&gt;
&lt;p&gt;This should update the item, but I believe it will trigger a new onAfterUpdate Event, so make sure you check for the presence of the related-property and&amp;nbsp;idOfrelatedItem&amp;nbsp;and only perform the update once.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>