<?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>How to call a server method with applyMethod() from a client method, and use the results coming back from server</title><link>https://www.aras.com/community/f/development/6000/how-to-call-a-server-method-with-applymethod-from-a-client-method-and-use-the-results-coming-back-from-server</link><description>Server Method : [Get_Identity_Details] Can run this and get results I want. Hard coded guid for test 
 Innovator inn = this.getInnovator(); string sessionuserid = this.getProperty(&amp;quot;sessionuser&amp;quot;,&amp;quot;invalid&amp;quot;); if (sessionuserid == &amp;quot;&amp;quot;){} 
 StringBuilder sql</description><dc:language>ja-JP</dc:language><generator>Telligent Community 12</generator><item><title>RE: How to call a server method with applyMethod() from a client method, and use the results coming back from server</title><link>https://www.aras.com/community/thread/2875?ContentTypeID=1</link><pubDate>Wed, 15 May 2019 19:23:13 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:4ca4a346-0f6b-4c6b-b61b-2f269a78f751</guid><dc:creator>Amitosh Tripathy</dc:creator><description>&lt;p&gt;perfect! thanks for the update. Works as expected now &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;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to call a server method with applyMethod() from a client method, and use the results coming back from server</title><link>https://www.aras.com/community/thread/2874?ContentTypeID=1</link><pubDate>Tue, 14 May 2019 21:23:03 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:aed4664b-8904-41f8-918a-12e5533eca75</guid><dc:creator>Christopher Gillis</dc:creator><description>&lt;p&gt;Hi amitosh,&lt;/p&gt;
&lt;p&gt;I believe you&amp;#39;re looking at the description of the&amp;nbsp;&lt;strong&gt;applyMethod&lt;/strong&gt; function available from the&amp;nbsp;&lt;strong&gt;Innovator&lt;/strong&gt; class in the IOM which does return an &lt;strong&gt;&lt;/strong&gt;Item. The functions available from the&amp;nbsp;&lt;strong&gt;aras&lt;/strong&gt; object in a JavaScript method don&amp;#39;t map directly with the functions available from the&amp;nbsp;&lt;strong&gt;Innovator&lt;/strong&gt; object in a server method even though some of them will&amp;nbsp;occasionally&amp;nbsp;share the same name.&lt;/p&gt;
&lt;p&gt;A JavaScript representation of the&amp;nbsp;&lt;strong&gt;Innovator&lt;/strong&gt; object is available through a client method, however. If we use this Innovator object (available from &lt;strong&gt;aras.IomInnovator)&lt;/strong&gt;, a&amp;nbsp;nicer way of writing the sample I provided in my last comment would instead be:&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&lt;strong&gt;&lt;/strong&gt;var res = aras.IomInnovator&lt;span&gt;.applyMethod(&lt;/span&gt;&lt;span&gt;&amp;quot;NOV_Identity_Details&amp;quot;&lt;/span&gt;&lt;span&gt;,&amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;quot;body&amp;quot;&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Since this function is called from an Innovator object,&amp;nbsp;the return value is an Item object, so it will save you from needing to any manual conversion from a string to an Item.&lt;/p&gt;
&lt;p&gt;Hope this helps!&lt;/p&gt;
&lt;p&gt;Chris&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to call a server method with applyMethod() from a client method, and use the results coming back from server</title><link>https://www.aras.com/community/thread/2873?ContentTypeID=1</link><pubDate>Tue, 14 May 2019 21:15:10 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:00c7ffdb-314a-44ba-91bf-b507b1e6c785</guid><dc:creator>Amitosh Tripathy</dc:creator><description>&lt;p&gt;Thanks Chris. Works now!!!&lt;/p&gt;
&lt;p&gt;But the method says it returns Item, is it returning &lt;span&gt;containing the item data&amp;nbsp;&lt;/span&gt;because its called from client?&lt;/p&gt;
&lt;pre&gt;&lt;span class="keyword"&gt;public&lt;/span&gt; &lt;span class="identifier"&gt;Item&lt;/span&gt; &lt;span class="identifier"&gt;applyMethod&lt;/span&gt;(
	&lt;span class="identifier"&gt;string&lt;/span&gt; &lt;span class="parameter"&gt;methodName&lt;/span&gt;,
	&lt;span class="identifier"&gt;string&lt;/span&gt; &lt;span class="parameter"&gt;body&lt;/span&gt;
)&lt;/pre&gt;
&lt;p&gt;getIdentityList - I tried this, but looping through the results and adding to the list took visible performance hit. Trying to convert to sql as I am going 2 levels in the Identity tree as you can see from SQL. Also, this piece of code need not go through access check as per our implementation&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to call a server method with applyMethod() from a client method, and use the results coming back from server</title><link>https://www.aras.com/community/thread/2872?ContentTypeID=1</link><pubDate>Tue, 14 May 2019 20:32:33 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:40d98c21-eec6-43d1-8ddf-148bf3945ece</guid><dc:creator>Christopher Gillis</dc:creator><description>&lt;p&gt;Hi amitosh,&lt;/p&gt;
&lt;p&gt;It appears that the result of the&amp;nbsp;&lt;strong&gt;aras.applyMethod&lt;/strong&gt; function is a string containing the item data returned by the server method. To put this into a more readable format, I&amp;#39;d recommend using code like below to load it into an IOM Item object.&lt;/p&gt;
&lt;div&gt;
&lt;div style="padding-left:30px;"&gt;&lt;span&gt;var&lt;/span&gt;&lt;span&gt; res = aras.applyMethod(&lt;/span&gt;&lt;span&gt;&amp;quot;NOV_Identity_Details&amp;quot;&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span&gt;&amp;quot;body&amp;quot;&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/div&gt;
&lt;div style="padding-left:30px;"&gt;&lt;span&gt;var&lt;/span&gt;&lt;span&gt; resItem = aras.&lt;/span&gt;&lt;span&gt;IomInnovator&lt;/span&gt;&lt;span&gt;.newItem(); // Create a new empty item&lt;/span&gt;&lt;/div&gt;
&lt;div style="padding-left:30px;"&gt;&lt;span&gt;resItem.loadAML(res); // and then load in the string returned from aras.applyMethod&lt;/span&gt;&lt;/div&gt;
&lt;div style="padding-left:30px;"&gt;&lt;span&gt;alert(resItem.getProperty(&lt;/span&gt;&lt;span&gt;&amp;quot;item_number&amp;quot;&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span&gt;&amp;quot;&amp;quot;&lt;/span&gt;&lt;span&gt;)); // so we can access the item data using a convenient API&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;You can then perform all your logic and checks using the&amp;nbsp;&lt;strong&gt;resItem&lt;/strong&gt; variable. With that being said, we recommend against using direct SQL inside of a server method as it bypasses the standard Aras permission model. Instead you could perform all of this logic inside of your client method by taking advantage of the standard&amp;nbsp;&lt;strong&gt;aras.getIdentityList()&lt;/strong&gt; function. This will return a list containing all of the identities the currently logged in user belongs to. This list is also built off of a recursive query, so it will get all a list of identities even if the user is a member of a member of a member, etc. The code for this might look something like below.&lt;/p&gt;
&lt;div&gt;
&lt;div style="padding-left:30px;"&gt;&lt;span&gt;var&lt;/span&gt;&lt;span&gt; myGroupIdentities = aras.&lt;/span&gt;&lt;span&gt;IomInnovator&lt;/span&gt;&lt;span&gt;.newItem(&lt;/span&gt;&lt;span&gt;&amp;quot;Identity&amp;quot;&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span&gt;&amp;quot;get&amp;quot;&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/div&gt;
&lt;div style="padding-left:30px;"&gt;&lt;span&gt;myGroupIdentities.setProperty(&lt;/span&gt;&lt;span&gt;&amp;quot;id&amp;quot;&lt;/span&gt;&lt;span&gt;, aras.getIdentityList());&lt;/span&gt;&lt;/div&gt;
&lt;div style="padding-left:30px;"&gt;&lt;span&gt;myGroupIdentities.setPropertyCondition(&lt;/span&gt;&lt;span&gt;&amp;quot;id&amp;quot;&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span&gt;&amp;quot;in&amp;quot;&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/div&gt;
&lt;div style="padding-left:30px;"&gt;&lt;span&gt;myGroupIdentities.setProperty(&lt;/span&gt;&lt;span&gt;&amp;quot;classification&amp;quot;&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span&gt;&amp;quot;Group&amp;quot;&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/div&gt;
&lt;div style="padding-left:30px;"&gt;&lt;span&gt;myGroupIdentities.setAttribute(&lt;/span&gt;&lt;span&gt;&amp;quot;select&amp;quot;&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span&gt;&amp;quot;id,keyed_name&amp;quot;&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/div&gt;
&lt;div style="padding-left:30px;"&gt;&lt;span&gt;myGroupIdentities = myGroupIdentities.apply();&lt;/span&gt;&lt;/div&gt;
&lt;/div&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>