<?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>Calculate a sum column and save property</title><link>https://www.aras.com/community/f/development/3990/calculate-a-sum-column-and-save-property</link><description>Hi

I&amp;#39;m new to javascript in ARAS and unfamiliar with the syntax.

I have created a new item type called &amp;#39;purchase order lines&amp;#39; containing some information of manufacturer parts and some additional information. The information is entered manually by the</description><dc:language>ja-JP</dc:language><generator>Telligent Community 12</generator><item><title>RE: Calculate a sum column and save property</title><link>https://www.aras.com/community/thread/2195?ContentTypeID=1</link><pubDate>Thu, 25 Oct 2018 09:51:07 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:64b5f15c-2b7b-4f02-9c4c-eb8319a64315</guid><dc:creator>cm</dc:creator><description>Hi Chris

We&amp;#39;re using Version 11.0 SP12 Build: 6920

My item type is called pr_PO_position and the respecive relationship item type is called pr_PO_pos.
At least, that&amp;#39;s how I understood ARAS.

Chris&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Calculate a sum column and save property</title><link>https://www.aras.com/community/thread/2194?ContentTypeID=1</link><pubDate>Thu, 25 Oct 2018 09:15:14 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:4384099f-326b-4284-9ffa-a6002c871ff3</guid><dc:creator>Christopher Gillis</dc:creator><description>Hi Chris,

Could you let us know what version of Aras Innovator you are using and whether &lt;strong&gt;po_lines&lt;/strong&gt; is the name of the RelationshipType or the related ItemType?

Chris

&lt;hr /&gt;

Christopher Gillis

Aras Labs Software Engineer&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Calculate a sum column and save property</title><link>https://www.aras.com/community/thread/2193?ContentTypeID=1</link><pubDate>Thu, 25 Oct 2018 06:02:25 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:dc479de4-03a2-4d2d-ab1b-4a9a40329d39</guid><dc:creator>cm</dc:creator><description>Hi Chris

I&amp;#39;ve modifyied your code to meet my specific filed names and tried both ways - as a client event &amp;#39;onAfterNew&amp;#39; or &amp;#39;onShowItem&amp;#39; and as a property event &amp;#39;onEditFinish&amp;#39;. Neither works.

This is what I have:
&lt;pre&gt;&lt;code&gt;// get item ID
var po_pos_id       = this.item.querySelector(&amp;quot;#&amp;quot; + relatedID);

// get item properties
var po_pos_quantity = parseFloat(aras.getItemProperty(po_pos_id, &amp;quot;pr_pos_quantity&amp;quot;));
var po_pos_price    = parseFloat(aras.getItemProperty(po_pos_id, &amp;quot;pr_pos_price&amp;quot;));
var po_pos_ppu      = parseFloat(aras.getItemProperty(po_pos_id, &amp;quot;pr_po_priceper&amp;quot;));

// make sure we have all the pieces to calculate the total
if (po_pos_quantity !== 0 &amp;amp;&amp;amp; !=isNaN(po_pos_quantity) &amp;amp;&amp;amp; po_pos_price !== 0 &amp;amp;&amp;amp; !=isNaN(po_pos_price) &amp;amp;&amp;amp; po_pos_ppu !== 0 &amp;amp;&amp;amp; !=isNaN(po_pos_ppu)) {
    // Calculate the total
    var total = po_pos_quantity * (po_pos_price / po_pos_ppu);
    
    // Set the total
    aras.setItemProperty(po_pos_id, &amp;quot;pr_pos_value&amp;quot;, total);
    
    // Refresh the form so this new value appears
    aras.uiReShowItemEx(this.item.id, this.item);
}&lt;/code&gt;&lt;/pre&gt;


When I added the code to the property event I couldn&amp;#39;t use the input grid anymore. Whenever I tried to jump from one field to another the form seemed busy and didn&amp;#39;t allow me to change the information once something was entered, mostly &amp;#39;NaN&amp;#39; for number fields. 

I have an item type called purchase_order. This item contains a related item type called po_lines which should contain single items with a description, quantity and so on. Therefore I think your suggested solution should work as this is in a relationship grid, shouldn&amp;#39;t it?

I&amp;#39;m doing something wrong, but I have no idea what it is.

Chris&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Calculate a sum column and save property</title><link>https://www.aras.com/community/thread/2192?ContentTypeID=1</link><pubDate>Tue, 23 Oct 2018 11:28:41 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:98c76145-67f5-4dfa-aedf-4a9d312784a4</guid><dc:creator>Christopher Gillis</dc:creator><description>Hi Chris,

The &lt;strong&gt;onEditFinish&lt;/strong&gt; event exists on the Properties themselves. You can open the property directly by navigating to the &lt;strong&gt;Properties&lt;/strong&gt; relationship tab of the ItemType, right-clicking on the property you want to open, and selecting &lt;strong&gt;View &amp;quot;Properties&amp;quot;&lt;/strong&gt;.

Chris

&lt;hr /&gt;

Christopher Gillis

Aras Labs Software Engineer&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Calculate a sum column and save property</title><link>https://www.aras.com/community/thread/2191?ContentTypeID=1</link><pubDate>Tue, 23 Oct 2018 11:20:54 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:cafa613a-bc4d-4b91-acad-e64bb9b7b86b</guid><dc:creator>cm</dc:creator><description>Hi Chris

Thanks for the sample code.

There is only one question. If I try to add the method to the client event in the item type &amp;#39;purchase order lines&amp;#39; I cannot find the event &amp;#39;onEditFinish&amp;#39;. All I see is &amp;#39;onBeforeNew&amp;#39;, &amp;#39;OnNew&amp;#39;,  &amp;#39;OnAfterNew&amp;#39; and &amp;#39;OnShowItem&amp;#39;.

&amp;nbsp;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Calculate a sum column and save property</title><link>https://www.aras.com/community/thread/2190?ContentTypeID=1</link><pubDate>Tue, 23 Oct 2018 11:01:40 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:d1c18406-4e59-456a-8898-80eec62e670a</guid><dc:creator>Christopher Gillis</dc:creator><description>Hi Chris,

So there&amp;#39;s two ways you can go about this. The easiest way would be to add an onBeforeUpdate server event that calculates the total each time that the item is saved. However, this means that the total you want to calculate won&amp;#39;t appear until after the user saves the item.

If you&amp;#39;d prefer the total to be updated dynamically, you could use code like the sample below from an &lt;strong&gt;onEditFinish&lt;/strong&gt; event on the Properties themselves.

&lt;pre&gt;&lt;code&gt;// Get the item
var po = this.item.querySelector(&amp;quot;#&amp;quot; + relatedID);
// Get the properties from the item
var quantity = parseInt(aras.getItemProperty(po, &amp;quot;quantity&amp;quot;));
var price = parseFloat(aras.getItemProperty(po, &amp;quot;price&amp;quot;));
var ppu = parseFloat(aras.getItemProperty(po, &amp;quot;price_per_unit&amp;quot;));
// make sure we have all the pieces to calculate the total
if (!!quantity &amp;amp;&amp;amp; !!price &amp;amp;&amp;amp; !!ppu) {
// Calculate the total
var total = quantity * (price / ppu);
// Set the total
aras.setItemProperty(po, &amp;quot;total&amp;quot;, total);
// Refresh the form so this new value appears
aras.uiReShowItemEx(this.item.id, this.item);
}&lt;/code&gt;&lt;/pre&gt;


Note that this sample code assumes that these properties are being updated from a relationship grid and not from a Form.

Chris

&lt;hr /&gt;

Christopher Gillis

Aras Labs Software Engineer&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>