<?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>Is there a way to write a server event that adds relationships by creating aml</title><link>https://www.aras.com/community/f/development/5933/is-there-a-way-to-write-a-server-event-that-adds-relationships-by-creating-aml</link><description>I have a form that I need to add relationships to initiatives and I want to create those relationships when the user saves the form. The Bold aml is what i want to add. 
 &amp;quot;&amp;lt;Item type=&amp;quot;Action Plan&amp;quot; typeId=&amp;quot;22E5726BF58743B4AEEA018086F2AD6E&amp;quot; id=&amp;quot;A5966C1DA4D5447A9A937FBED748233E</description><dc:language>ja-JP</dc:language><generator>Telligent Community 12</generator><item><title>RE: Is there a way to write a server event that adds relationships by creating aml</title><link>https://www.aras.com/community/thread/2784?ContentTypeID=1</link><pubDate>Thu, 18 Apr 2019 12:12:31 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:d6483a54-31fe-46fe-b083-809b31a1e5d9</guid><dc:creator>Meismart</dc:creator><description>&lt;p&gt;assuming &amp;#39;this&amp;#39; is the item you wish to save, I would suggest you try something similar to:&lt;/p&gt;
&lt;p&gt;//Get the related_id&lt;br /&gt;var sp_target_id = this.getRelationship(&amp;quot;SP Target&amp;quot;).getRelatedItemID(); //assumes 1 relationship item of type &amp;quot;SP Target&amp;quot;&lt;/p&gt;
&lt;p&gt;//create the relationship Item&lt;br /&gt;var target_string = &amp;quot;&amp;lt;Relationships&amp;gt;&amp;quot;;&lt;br /&gt;target_string += &amp;quot;&amp;lt;Item type=&amp;#39;AP Initiative Target&amp;#39; action=&amp;#39;add&amp;#39;&amp;gt;&amp;quot;;&lt;br /&gt;target_string += &amp;quot;&amp;lt;related_id&amp;gt;&amp;quot; +sp_target_id+ &amp;quot;&amp;lt;/related_id&amp;gt;&amp;quot;;&lt;br /&gt;target_string += &amp;quot;&amp;lt;/Item&amp;gt;&amp;quot;;&lt;br /&gt;target_string += &amp;quot;&amp;lt;/Relationships&amp;gt;&amp;quot;;&lt;/p&gt;
&lt;p&gt;//Load the AML into a new Item&lt;br /&gt;Var targ = this.newItem();&lt;br /&gt;targ.loadAML(target_string)&lt;/p&gt;
&lt;p&gt;//Add the relationship to the context items AML&lt;br /&gt;this.addRelationship(targ);&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Note: I have not tested this, but it shows the approach I would take if I was to do something similar.&lt;/p&gt;
&lt;p&gt;Many thanks,&lt;br /&gt;Martin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Is there a way to write a server event that adds relationships by creating aml</title><link>https://www.aras.com/community/thread/2758?ContentTypeID=1</link><pubDate>Wed, 10 Apr 2019 05:45:25 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:c17b5752-edb6-4220-b63e-16e5ddb69a08</guid><dc:creator>jukkatlehtinen</dc:creator><description>&lt;p&gt;Hi,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Yes - it&amp;#39;s possible - but I think there is something missing from your AML.&lt;/p&gt;
&lt;p&gt;Here is example:&lt;/p&gt;
&lt;p&gt;&amp;lt;Item type=&amp;quot;Part BOM&amp;quot; action=&amp;quot;add&amp;quot;&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;lt;related_id&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;lt;Item type=&amp;quot;Part&amp;quot; action=&amp;quot;get&amp;quot;&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;id&amp;gt;6411401035053&amp;lt;/id&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;lt;/Item&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;lt;/related_id&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;lt;source_id&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;lt;Item type=&amp;quot;Part&amp;quot; action=&amp;quot;get&amp;quot;&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;id&amp;gt;6411401035050&amp;lt;/id&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;lt;/Item&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;lt;/source_id&amp;gt;&lt;br /&gt; &amp;lt;/Item&amp;gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;So you need to have:&lt;/p&gt;
&lt;p&gt;* Relationship type - in my example Part BOM - and I think in your AML it should be &amp;#39;AP Initiative Target&amp;#39; (and action=&amp;#39;&amp;#39;add&amp;#39; since you are creating this _relationship_.&lt;/p&gt;
&lt;p&gt;* source item - and action=&amp;#39;&lt;strong&gt;get&lt;/strong&gt;&amp;#39; tells that this item is already in the Aras (if not, you might want to create it with action=&amp;#39;&lt;strong&gt;add&lt;/strong&gt;&amp;#39;)&lt;/p&gt;
&lt;p&gt;* related_id - the child of the relationship (and again, action=&amp;#39;get&amp;#39; is actually search which returns (at least in this case) only one item)&lt;/p&gt;
&lt;p&gt;You can test your AML with Nash (it comes with Aras installation) can be found:&amp;nbsp;http://[your server]/InnovatorServer/client/scripts/nash.aspx&amp;nbsp;- if you used the default URL:s when installing.&lt;/p&gt;
&lt;p&gt;Hope this helps,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;//Jukka.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>