<?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 pass items in applyMethod?</title><link>https://www.aras.com/community/f/development/3974/how-to-pass-items-in-applymethod</link><description>Hi,

I have a couple of huge server Methods, that share around 90% of the same code. So I want to unify them into one large Method, and use more compact calling Methods.

My current problem is to past the context Item(s) to the main Method. When I call</description><dc:language>ja-JP</dc:language><generator>Telligent Community 12</generator><item><title>RE: How to pass items in applyMethod?</title><link>https://www.aras.com/community/thread/2162?ContentTypeID=1</link><pubDate>Wed, 17 Oct 2018 04:24:11 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:d0dbb80e-c0f2-4796-b056-7a230cfdf6b3</guid><dc:creator>AngelaIp</dc:creator><description>Hi Andreas,

no, of course I didn´t try that...
Many thanks for this one, this version now does the job pretty well:

&lt;pre&gt;&lt;code&gt;Innovator inn = this.getInnovator();
this.setProperty(&amp;quot;keyword_&amp;quot;,&amp;quot;INSERT&amp;quot;);
Item res = this.apply(&amp;quot;MyMainMethod&amp;quot;);
if (res.isError())
{
    XmlDocument xDoc = new XmlDocument();
    xDoc.LoadXml(res.ToString());
    string faultstring = xDoc.SelectSingleNode(&amp;quot;//faultstring&amp;quot;).InnerText;
    return inn.newError(&amp;quot;Error: &amp;quot; + faultstring);
}
return res;&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to pass items in applyMethod?</title><link>https://www.aras.com/community/thread/2161?ContentTypeID=1</link><pubDate>Wed, 17 Oct 2018 02:56:00 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:19a8cdb6-ffc1-4a68-bf02-925e2b94478c</guid><dc:creator>Andreas S.</dc:creator><description>Hi Angela,

have you tried this?
&lt;pre&gt;&lt;code&gt;
this.apply(&amp;quot;MyMainMethod&amp;quot;);
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to pass items in applyMethod?</title><link>https://www.aras.com/community/thread/2160?ContentTypeID=1</link><pubDate>Tue, 16 Oct 2018 11:11:48 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:1cec27db-d674-4db4-af17-0ce8e349624e</guid><dc:creator>AngelaIp</dc:creator><description>Hi Andreas,

thanks for your help! Your code basically works, but I still have some trouble to hand over the complete Item that calls the Method:

&lt;pre&gt;&lt;code&gt;// Calling Method
Innovator inn = this.getInnovator();
Item myItem = this.newItem(this.getAttribute(&amp;quot;type&amp;quot;), &amp;quot;MyMainMethod&amp;quot;);
myItem.setID(this.getID());
myItem.setProperty(&amp;quot;keyword_&amp;quot;,&amp;quot;INSERT&amp;quot;);
Item results = myItem.apply();
if (results.isError())
{
    return inn.newError(&amp;quot;Error while Insert Data. &amp;quot; + results);
}
return results;&lt;/code&gt;&lt;/pre&gt;


&lt;pre&gt;&lt;code&gt;
// Main Method
Innovator inn = this.getInnovator();
string thisItemTypeName = this.getItemByIndex(0).getAttribute(&amp;quot;type&amp;quot;,&amp;quot;&amp;quot;); // work! will return type of calling Item instead of Method
// Parameters passed with Method call
string keyword = this.getProperty(&amp;quot;keyword_&amp;quot;,&amp;quot;invalid&amp;quot;); // works
if (keyword == &amp;quot;...&amp;quot;){}

// Get properties from calling Item
int count = this.getItemCount(); // don´t work
string pn = this.getItemByIndex(0).getProperty(&amp;quot;item_number&amp;quot;, &amp;quot;empty&amp;quot;); // don´t work, will always be empty, as &amp;quot;this&amp;quot; doesn´t contain the complete original Item.&lt;/code&gt;&lt;/pre&gt;


It would be possible to extend the calling Method to handover more properties. But this would make the calling Method more complex. One alternative is to extend the Method call so it contains the original Item: 
&lt;code&gt;myItem.setProperty(&amp;quot;myitem_&amp;quot;, this);&lt;/code&gt;

But I am not sure if passing &amp;quot;this&amp;quot; is really the best solution. This will move around a lot of data, as the Method shall apply to multiple items.&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to pass items in applyMethod?</title><link>https://www.aras.com/community/thread/2159?ContentTypeID=1</link><pubDate>Tue, 16 Oct 2018 07:39:14 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:25dc4f21-d626-48e4-a732-b487865bd9af</guid><dc:creator>Andreas S.</dc:creator><description>Hi Angela,

I do not know if I understood you correctly but maybe this (from Aras Programmer&amp;#39;s Guide) could help you:

4.1 Item Actions Extend the Item Class
One purpose for Methods is to extend the Item Class. Methods extend the Item Class when they are bound as the related Item for ‘Item Action’ relationships on the ItemType. In the AML the Method name is the action attribute name for the Item tag.
&amp;lt;Item type=&amp;quot;My ItemType&amp;quot; action=&amp;quot;My Method&amp;quot; id=&amp;quot;…&amp;quot;/&amp;gt;
The Method could be called using the IOM like this (all three examples below are equivalent and are written in C#):

&lt;pre&gt;&lt;code&gt;
1) Item myItem = this.newItem(&amp;quot;My ItemType&amp;quot;, &amp;quot;My Method&amp;quot;);
myItem.setID(this.getID());
Item results = myItem.apply();
2) Item myItem = this.newItem(&amp;quot;My ItemType&amp;quot;);
myItem.setID(this.getID());
Item results = myItem.apply(&amp;quot;My Method&amp;quot;);
3) Item myItem = this.newItem();
myItem.setID(this.getID());
myItem.setType(&amp;quot;My ItemType&amp;quot;);
myItem.setAction(&amp;quot;My Method&amp;quot;);
Item results = myItem.apply();
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>