<?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>Getting an item property in onChangedCell from a recently created relationship vs existing relationship</title><link>https://www.aras.com/community/f/development/5756/getting-an-item-property-in-onchangedcell-from-a-recently-created-relationship-vs-existing-relationship</link><description>I&amp;#39;m running a method on the property event &amp;quot;onChangedCell&amp;quot;. When the method is called on a newly created related item, the following statement successfully get&amp;#39;s the property: 
 var my_item = parent.item.querySelector(&amp;quot;#&amp;quot; + relatedID); var my_property</description><dc:language>ja-JP</dc:language><generator>Telligent Community 12</generator><item><title>RE: Getting an item property in onChangedCell from a recently created relationship vs existing relationship</title><link>https://www.aras.com/community/thread/2562?ContentTypeID=1</link><pubDate>Wed, 13 Feb 2019 15:21:35 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:2db3b251-b67d-4746-9a47-3eaa9152f464</guid><dc:creator>Kenneth Ballash</dc:creator><description>&lt;p&gt;Thanks Chris! I&amp;#39;m using 11sp12. I did some digging and it turns out all my test cases happened to begin with a non-number character. So this didn&amp;#39;t fix the problem I was running into. However, I created some more items till I got a number as the first&amp;nbsp;character and the code you provided helped with that case. Thank you for your help resolving another problem before it even happened!&amp;nbsp;&lt;span class="emoticon" data-url="https://www.aras.com/community/cfs-file/__key/system/emoji/1f642.svg" title="Slight smile"&gt;&amp;#x1f642;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Trying to find out more about when/why the method fails, I dug more into the debugger and found that I&amp;#39;m not always getting an item element back from &lt;em&gt;parent.item.querySelector()&lt;/em&gt;, sometimes I&amp;#39;m just getting the relatedID back:&amp;nbsp;&lt;/p&gt;
&lt;p&gt;When it works:&lt;br /&gt;&lt;em&gt;my_item&amp;nbsp;= &lt;strong&gt;item&lt;/strong&gt;#9D10DBF4F748479981FD06B4CC4C31B6 {namespaceURI: null, prefix: null, localName: &amp;quot;Item&amp;quot;, tagName: &amp;quot;Item&amp;quot;, id: &amp;quot;9D10DBF4F748479981FD06B4CC4C31B6&amp;quot;, &amp;hellip;}&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;When it doesn&amp;#39;t work:&amp;nbsp;&lt;br /&gt;&lt;em&gt;my_item&amp;nbsp;= &lt;strong&gt;related_id&lt;/strong&gt;#9D10DBF4F748479981FD06B4CC4C31B6 {namespaceURI: null, prefix: null, localName: &amp;quot;related_id&amp;quot;, tagName: &amp;quot;related_id&amp;quot;, id: &amp;quot;9D10DBF4F748479981FD06B4CC4C31B6&amp;quot;, &amp;hellip;}&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I realized I needed to define a better selector to get the correct element from the dom since &lt;em&gt;querySelector()&lt;/em&gt; just returns the first match. I updated the code Chris provided to include updates to the CSS selector:&lt;/p&gt;
&lt;div class="content-scrollable-wrapper content-scrollable-wrapper-scrolled" style="overflow:auto;"&gt;
&lt;pre&gt;&lt;code&gt;var my_item;
var firstChar = relatedID.substring(0, 1);
if (isNaN(parseInt(firstChar))){
    my_item = parent.item.querySelector(&lt;strong&gt;&amp;quot;Item[id=" + relatedID + "]&amp;quot;&lt;/strong&gt;);
}
else {
    // If the ID begins with a number, we need to escape that character
    firstChar = &amp;quot;\\3&amp;quot; + firstChar;
    var restOfId = relatedID.substring(1);
    my_item = parent.item.querySelector(&lt;strong&gt;&amp;quot;Item[id=" + firstChar + " " + restOfId + "]&amp;quot;&lt;/strong&gt;);
}
var my_property = aras.getItemProperty(my_item, &amp;quot;item_number&amp;quot;);
alert(my_property);
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;This seems to have resolved the issue I was having and the issue Chris preemptively helped with.&lt;/p&gt;
&lt;p&gt;Thanks again Chris!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Getting an item property in onChangedCell from a recently created relationship vs existing relationship</title><link>https://www.aras.com/community/thread/2552?ContentTypeID=1</link><pubDate>Tue, 12 Feb 2019 14:33:41 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:b30d99e0-9311-40ad-895e-e77ff624abeb</guid><dc:creator>Christopher Gillis</dc:creator><description>&lt;p&gt;Hi Ken,&lt;/p&gt;
&lt;p&gt;I tried running this in an 11.0 SP15 instance I have installed locally, and I was able to get the existing related item using your sample above. I think the issue you may be running into is that the querySelector needs special formatting for IDs that begin with a number. You can see the sample below for how you might handle these kinds of IDs.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;var my_item;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;var firstChar = relatedID.substring(0, 1);&lt;br /&gt;if (isNaN(parseInt(firstChar)))&lt;br /&gt;{&lt;br /&gt; my_item = parent.item.querySelector(&amp;quot;#&amp;quot; + relatedID)&lt;br /&gt;}&lt;br /&gt;else&lt;br /&gt;{&lt;br /&gt; // If the ID begins with a number, we need to escape that character&lt;br /&gt; firstChar = &amp;quot;\\3&amp;quot; + firstChar;&lt;br /&gt; var restOfId = relatedID.substring(1);&lt;br /&gt; my_item = parent.item.querySelector(&amp;quot;#&amp;quot; + firstChar + &amp;quot; &amp;quot; + restOfId);&lt;br /&gt;}&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;var my_property = aras.getItemProperty(my_item, &amp;quot;item_number&amp;quot;);&lt;br /&gt;alert(my_property);&lt;/p&gt;
&lt;p&gt;Chris&lt;/p&gt;
&lt;p&gt;Christopher Gillis&lt;/p&gt;
&lt;p&gt;Aras Labs Software Engineer&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>