<?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>Get parent of context item in relationship action</title><link>https://www.aras.com/community/f/development/37046/get-parent-of-context-item-in-relationship-action</link><description>Hi all, 
 
 I am using an action from a relationship grid which is driven by the PE_GetSelectedItems method. I need to get a handle on the parent item specifically as it looks like &amp;quot;this&amp;quot; returns a collection of all items open when used from this kind</description><dc:language>ja-JP</dc:language><generator>Telligent Community 12</generator><item><title>RE: Get parent of context item in relationship action</title><link>https://www.aras.com/community/thread/7834?ContentTypeID=1</link><pubDate>Wed, 15 Dec 2021 11:42:43 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:b3b28b28-7d1a-41e5-975e-db05c71be270</guid><dc:creator>alaxala</dc:creator><description>&lt;p&gt;I found the problem. XmlNode.appendChild() moves the node, not copy. And next time the ccItem&amp;nbsp;no longer has the property &amp;quot;source_id&amp;quot; and &amp;quot;source&amp;quot; becomes undefined.&lt;/p&gt;
&lt;p&gt;This is final version, I hope )).&amp;nbsp;I also added a check for re-adding a &amp;quot;source_id&amp;quot; property.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="javascript"&gt;if (ccItem) {
	var source = ccItem.selectSingleNode(&amp;quot;source_id&amp;quot;).cloneNode(true);
	ccItem = aras.getRelatedItem(ccItem);
	if (!ccItem.selectSingleNode(&amp;quot;source_id&amp;quot;)) ccItem.appendChild(source);
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;If you use item.getProperty you get the string with parent item id. If you use getPropertyItem you get parent item. But with only &amp;quot;type&amp;quot;, &amp;quot;keyed_name&amp;quot; attributes and &amp;quot;id&amp;quot; property. It will not have any more properties&amp;nbsp;since they were not in the original &amp;quot;source_id&amp;quot; property.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Get parent of context item in relationship action</title><link>https://www.aras.com/community/thread/7831?ContentTypeID=1</link><pubDate>Tue, 14 Dec 2021 17:19:17 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:14e46e46-54a4-4ba2-9ba0-00cf0beef3b4</guid><dc:creator>Morgan</dc:creator><description>&lt;p&gt;I think I am a little closer. I have noticed that if I ran the method twice, it runs ok the first time, but fails the second time. If I refresh the parent, it is working fine again. I think I will need to add a refresh into my method. Going to try this.&lt;/p&gt;
&lt;p&gt;Also, I am assuming I should be able to reference this property on the subsequent called method via the item.getProperty(&amp;quot;source_id&amp;quot;) or should I use .getPropertyItem()?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Get parent of context item in relationship action</title><link>https://www.aras.com/community/thread/7816?ContentTypeID=1</link><pubDate>Fri, 10 Dec 2021 08:27:39 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:9746f434-64ba-4269-ae39-4e2c1b8a97ec</guid><dc:creator>alaxala</dc:creator><description>&lt;p&gt;It is very strange. I tried it myself. It works. Maybe you are changing the wrong block. There is a similar section of code above.&amp;nbsp;Here is bigger piece of PE_GetSelectedItems with changes:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="javascript"&gt;if (isRelationship) {
	var parentId = this.getProperty(&amp;quot;source_id&amp;quot;, &amp;quot;&amp;quot;);
	var parentItem = aras.getItemById(sourceItemTypeName, parentId, 0);
	if (parentItem) {
		ccItem = parentItem.selectSingleNode(&amp;quot;Relationships/Item[@id=&amp;#39;&amp;quot; + idArray[k] + &amp;quot;&amp;#39;]&amp;quot;);

		//If item isn&amp;#39;t cached, get 
		if (!ccItem) {
			ccItem = aras.getItemById(thisType, idArray[k], 0);
		}

		//get related Part
		if (ccItem) {
			var source = ccItem.selectSingleNode(&amp;quot;source_id&amp;quot;); // add this
			ccItem = aras.getRelatedItem(ccItem);
			ccItem.appendChild(source);     // and this
		}
	}
}
&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Get parent of context item in relationship action</title><link>https://www.aras.com/community/thread/7814?ContentTypeID=1</link><pubDate>Thu, 09 Dec 2021 20:34:58 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:64dd0049-ba0e-4e86-bcab-0b93db71f219</guid><dc:creator>Morgan</dc:creator><description>&lt;p&gt;Thanks for responding again. Even with these changes, the same failure error is presented.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Get parent of context item in relationship action</title><link>https://www.aras.com/community/thread/7812?ContentTypeID=1</link><pubDate>Thu, 09 Dec 2021 10:02:04 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:0090adfe-570b-45ab-a894-ef265cf0f366</guid><dc:creator>alaxala</dc:creator><description>&lt;p&gt;Sorry, I&amp;nbsp;forgot&amp;nbsp;as always&amp;nbsp;that Javascript Item class is not the same as server-side Item class. Try this:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="javascript"&gt;if (ccItem) {
	var source = ccItem.selectSingleNode(&amp;quot;source_id&amp;quot;);
	ccItem = aras.getRelatedItem(ccItem);
	ccItem.appendChild(source);
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;You get the parent item as &amp;quot;source_id&amp;quot; property.&lt;/p&gt;
&lt;div style="left:55px;position:absolute;top:23px;" id="gtx-trans"&gt;
&lt;div class="gtx-trans-icon"&gt;&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Get parent of context item in relationship action</title><link>https://www.aras.com/community/thread/7811?ContentTypeID=1</link><pubDate>Wed, 08 Dec 2021 22:05:58 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:68c9b118-9f78-4541-b5e4-4893ccadd993</guid><dc:creator>Morgan</dc:creator><description>&lt;p&gt;Thanks for this. I do need both properties however when trying to set a fake property to pass, the PE_GetSelectedItems method fails with the error&amp;nbsp;&lt;span&gt;aras_object: &amp;quot;undefined&amp;quot; : &amp;quot;undefined&amp;quot;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Get parent of context item in relationship action</title><link>https://www.aras.com/community/thread/7805?ContentTypeID=1</link><pubDate>Tue, 07 Dec 2021 06:34:22 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:72981599-1a68-4e86-962d-41c7db2b2d8c</guid><dc:creator>alaxala</dc:creator><description>&lt;p&gt;Ok. I understood.&lt;/p&gt;
&lt;p&gt;PE_GetSelectedItems returns related items if it called from relationships grid. Well, you can use your own modified version of PE_GetSelectedItems for this action. All you need is comment out lines 84-86 in the original:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="javascript"&gt;if (ccItem) {
	ccItem = aras.getRelatedItem(ccItem);
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;You get the relationship items instead of related items and can use source_id property.&lt;/p&gt;
&lt;p&gt;Or, if you need both, you can use fake property:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="javascript"&gt;if (ccItem) {
    var parent = ccItem.getPropertyItem(&amp;quot;source_id&amp;quot;);
	ccItem = aras.getRelatedItem(ccItem);
	ccItem.setPropertyItem(&amp;quot;parent&amp;quot;, parent);
}&lt;/pre&gt;&lt;/p&gt;
&lt;div style="left:55px;position:absolute;top:204px;" id="gtx-trans"&gt;
&lt;div class="gtx-trans-icon"&gt;&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Get parent of context item in relationship action</title><link>https://www.aras.com/community/thread/7804?ContentTypeID=1</link><pubDate>Mon, 06 Dec 2021 16:55:17 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:def1197f-debc-4cbc-a505-3e915f6bc8c1</guid><dc:creator>Morgan</dc:creator><description>&lt;p&gt;I thought of this however of the relationship&amp;nbsp;item I am trying to capture the parent of may have multiple parent relationships.&lt;/p&gt;
&lt;p&gt;As far as I know, the&amp;nbsp;&lt;span&gt;PE_GetSelectedItems will return the item selected in the grid so I am wondering how to specifically get the parent which is active when I use my action that captures the context item via PE_GetSelectedItems&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Get parent of context item in relationship action</title><link>https://www.aras.com/community/thread/7769?ContentTypeID=1</link><pubDate>Wed, 24 Nov 2021 08:22:00 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:a3409494-f5bf-481f-b3ea-7292c5a585bc</guid><dc:creator>alaxala</dc:creator><description>&lt;p&gt;rItem.getProperty(&amp;quot;source_id&amp;quot;);&lt;/p&gt;
&lt;p&gt;or i misunderstood?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>