<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question Need to calculate the numeric sum values from multiple fields in Developer forum</title>
    <link>https://www.servicenow.com/community/developer-forum/need-to-calculate-the-numeric-sum-values-from-multiple-fields/m-p/1358571#M15497</link>
    <description>&lt;P&gt;I have four fields that have dropdown values of 1, 2 ,3. I need to know how to add all the values that were selected in the fields and have the total populate in another field. Would I have to modify the 'Overall Reseach Score' dictionary item and write a script in the Calculated Value tab?&lt;/P&gt;
&lt;P&gt;Fields:&lt;/P&gt;
&lt;OL&gt;&lt;LI&gt;Strategic Alignment (dropdown selections 1-3)&lt;/LI&gt;&lt;LI&gt;Community Support (dropdown selections 1-3)&lt;/LI&gt;&lt;LI&gt;Institutional Risk (dropdown selections 1-3)&lt;/LI&gt;&lt;LI&gt;Improve Capabilities (dropdown selections 1-3)&lt;/LI&gt;&lt;LI&gt;Overall Research Score (Totals field)&lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;So if each of the selected values were 1. Then the 'Overall Research Score' would be 4.&lt;/P&gt;</description>
    <pubDate>Thu, 16 Apr 2020 19:48:24 GMT</pubDate>
    <dc:creator>Raul Luna1</dc:creator>
    <dc:date>2020-04-16T19:48:24Z</dc:date>
    <item>
      <title>Need to calculate the numeric sum values from multiple fields</title>
      <link>https://www.servicenow.com/community/developer-forum/need-to-calculate-the-numeric-sum-values-from-multiple-fields/m-p/1358571#M15497</link>
      <description>&lt;P&gt;I have four fields that have dropdown values of 1, 2 ,3. I need to know how to add all the values that were selected in the fields and have the total populate in another field. Would I have to modify the 'Overall Reseach Score' dictionary item and write a script in the Calculated Value tab?&lt;/P&gt;
&lt;P&gt;Fields:&lt;/P&gt;
&lt;OL&gt;&lt;LI&gt;Strategic Alignment (dropdown selections 1-3)&lt;/LI&gt;&lt;LI&gt;Community Support (dropdown selections 1-3)&lt;/LI&gt;&lt;LI&gt;Institutional Risk (dropdown selections 1-3)&lt;/LI&gt;&lt;LI&gt;Improve Capabilities (dropdown selections 1-3)&lt;/LI&gt;&lt;LI&gt;Overall Research Score (Totals field)&lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;So if each of the selected values were 1. Then the 'Overall Research Score' would be 4.&lt;/P&gt;</description>
      <pubDate>Thu, 16 Apr 2020 19:48:24 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/need-to-calculate-the-numeric-sum-values-from-multiple-fields/m-p/1358571#M15497</guid>
      <dc:creator>Raul Luna1</dc:creator>
      <dc:date>2020-04-16T19:48:24Z</dc:date>
    </item>
    <item>
      <title>Re: Need to calculate the numeric sum values from multiple fields</title>
      <link>https://www.servicenow.com/community/developer-forum/need-to-calculate-the-numeric-sum-values-from-multiple-fields/m-p/1358572#M15498</link>
      <description>&lt;P&gt;Calculated fields are not good from performance point of view. Calculated field calculates the value each time a record is read.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Rather an insert/update business rule are better option. I believe in this case you can use before business rule on the table.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="background-color: #ffff00;"&gt;Please mark my answer correct/helpful, If it helped you.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Apr 2020 20:35:50 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/need-to-calculate-the-numeric-sum-values-from-multiple-fields/m-p/1358572#M15498</guid>
      <dc:creator>rajneeshbaranwa</dc:creator>
      <dc:date>2020-04-16T20:35:50Z</dc:date>
    </item>
    <item>
      <title>Re: Need to calculate the numeric sum values from multiple fields</title>
      <link>https://www.servicenow.com/community/developer-forum/need-to-calculate-the-numeric-sum-values-from-multiple-fields/m-p/1358573#M15499</link>
      <description>&lt;P&gt;Hi Raul,&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;If you want it to be a client side operation, if performance is not the issue and if you do not want to use business rules, you can do this.&lt;BR /&gt;You can write 4 client script on the table, 1 onLoad and 3 onChange for each of the fields.&lt;BR /&gt;Then you can use the below code to include in each of the scripts.&lt;BR /&gt;Please replace the values('field1','field2'.....) with the necessary column or field names in the table.&lt;/P&gt;
&lt;PRE class="language-markup"&gt;&lt;CODE&gt;function onLoad() { //Similary for onChange
   //Type appropriate comment here, and begin script below
	
	var strategicAlignment =  g_form.getValue('field1');
	var communitySupport =  g_form.getValue('field2');
	var institutionalRisk =  g_form.getValue('field3');
	var improveCapabilities = g_form.getValue('field4');
	var researchScore = parseInt(strategicAlignment) + parseInt(communitySupport) + parseInt(institutionalRisk) + parseInt(improveCapabilities);
	g_form.setValue('total_field', researchScore );
	
}&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Please mark my answer correct and helpful if it works.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;-Akash Gurram&lt;/P&gt;</description>
      <pubDate>Thu, 16 Apr 2020 20:39:48 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/need-to-calculate-the-numeric-sum-values-from-multiple-fields/m-p/1358573#M15499</guid>
      <dc:creator>Akash Gurram1</dc:creator>
      <dc:date>2020-04-16T20:39:48Z</dc:date>
    </item>
    <item>
      <title>Re: Need to calculate the numeric sum values from multiple fields</title>
      <link>https://www.servicenow.com/community/developer-forum/need-to-calculate-the-numeric-sum-values-from-multiple-fields/m-p/1358574#M15500</link>
      <description>&lt;P&gt;Hi rajneeshbaranwal,&lt;/P&gt;
&lt;P&gt;How would the business rule look like if i wanted to use that option?&lt;/P&gt;</description>
      <pubDate>Fri, 17 Apr 2020 12:32:01 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/need-to-calculate-the-numeric-sum-values-from-multiple-fields/m-p/1358574#M15500</guid>
      <dc:creator>Raul Luna1</dc:creator>
      <dc:date>2020-04-17T12:32:01Z</dc:date>
    </item>
    <item>
      <title>Re: Need to calculate the numeric sum values from multiple fields</title>
      <link>https://www.servicenow.com/community/developer-forum/need-to-calculate-the-numeric-sum-values-from-multiple-fields/m-p/1358575#M15501</link>
      <description>&lt;P&gt;Hi Akash,&lt;/P&gt;
&lt;P&gt;So i created onChange client scripts for each of the following fields like you recommended: Strategic alignment, Community support, Institutional risk, Improve capabilities.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper"&gt;&lt;img src="https://www.servicenow.com/community/s/skins/images/4F5658DC0F5F35C05380FC6974FE8B1A/responsive_peak/images/image_not_found.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;I also created an onLoad script with the same code. When i load the page i'm getting errors on each of the fields. Sorry i'm not coder so maybe I misinterpreted something in the code.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper"&gt;&lt;img src="https://www.servicenow.com/community/s/skins/images/4F5658DC0F5F35C05380FC6974FE8B1A/responsive_peak/images/image_not_found.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper"&gt;&lt;img src="https://www.servicenow.com/community/s/skins/images/4F5658DC0F5F35C05380FC6974FE8B1A/responsive_peak/images/image_not_found.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Apr 2020 12:45:07 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/need-to-calculate-the-numeric-sum-values-from-multiple-fields/m-p/1358575#M15501</guid>
      <dc:creator>Raul Luna1</dc:creator>
      <dc:date>2020-04-17T12:45:07Z</dc:date>
    </item>
    <item>
      <title>Re: Need to calculate the numeric sum values from multiple fields</title>
      <link>https://www.servicenow.com/community/developer-forum/need-to-calculate-the-numeric-sum-values-from-multiple-fields/m-p/1358576#M15502</link>
      <description>&lt;P&gt;Hi Raul,&lt;BR /&gt;&lt;BR /&gt;I see a mistake in the var researchScore part of the code. You should be using the declared variables in the parseInt() function.&lt;/P&gt;
&lt;P&gt;Please replace it with the following&lt;/P&gt;
&lt;PRE class="language-markup"&gt;&lt;CODE&gt;var researchScore = parseInt(strategicAlignment) + parseInt(communitySupport) + parseInt(institutionalRisk) + parseInt(improveCapabilities);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Hope that solves the problem.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Apr 2020 14:02:59 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/need-to-calculate-the-numeric-sum-values-from-multiple-fields/m-p/1358576#M15502</guid>
      <dc:creator>Akash Gurram1</dc:creator>
      <dc:date>2020-04-17T14:02:59Z</dc:date>
    </item>
    <item>
      <title>Re: Need to calculate the numeric sum values from multiple fields</title>
      <link>https://www.servicenow.com/community/developer-forum/need-to-calculate-the-numeric-sum-values-from-multiple-fields/m-p/1358577#M15503</link>
      <description>&lt;P&gt;Table = "Your table Name";&lt;/P&gt;
&lt;P&gt;When = Before;&lt;/P&gt;
&lt;P&gt;Both Insert and Update will be true;&lt;/P&gt;
&lt;P&gt;Script will be as below. Please note business rules apply whenever we make changes to the table, It could be using REST API, Import Set , Form update or list update while client script applies only on form changes.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I always prefer business rules for this kind of requirement.&lt;/P&gt;
&lt;P&gt;var value1 = 0 ;&lt;/P&gt;
&lt;P&gt;value2 = 0;&lt;/P&gt;
&lt;P&gt;value3=0;&lt;/P&gt;
&lt;P&gt;value4=0;&lt;/P&gt;
&lt;P&gt;if (current.field1)&lt;/P&gt;
&lt;P&gt;{value1 = current.getValue(field1);}&lt;/P&gt;
&lt;P&gt;if (current.field2)&lt;/P&gt;
&lt;P&gt;{value2 = current.getValue(field2);}&lt;/P&gt;
&lt;P&gt;if (current.field3)&lt;/P&gt;
&lt;P&gt;{value3 = current.getValue(field3);}&lt;/P&gt;
&lt;P&gt;if (Current.field4)&lt;/P&gt;
&lt;P&gt;{value4 = current.getValue(field3);}&lt;/P&gt;
&lt;P&gt;current.Overall Research Score = parseInt(value1) +&amp;nbsp;&amp;nbsp;&amp;nbsp;parseInt(value2) +&amp;nbsp;&amp;nbsp;parseInt(value3) +&amp;nbsp;&amp;nbsp;parseInt(value4) +&lt;/P&gt;</description>
      <pubDate>Fri, 17 Apr 2020 15:27:34 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/need-to-calculate-the-numeric-sum-values-from-multiple-fields/m-p/1358577#M15503</guid>
      <dc:creator>rajneeshbaranwa</dc:creator>
      <dc:date>2020-04-17T15:27:34Z</dc:date>
    </item>
    <item>
      <title>Re: Need to calculate the numeric sum values from multiple fields</title>
      <link>https://www.servicenow.com/community/developer-forum/need-to-calculate-the-numeric-sum-values-from-multiple-fields/m-p/1358578#M15504</link>
      <description>&lt;P&gt;Hi Raul,&lt;BR /&gt;&lt;BR /&gt;Did the above answer work for you?&lt;/P&gt;
&lt;P&gt;Please mark my solution correct and helpful if it did the work for you.&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;Akash Gurram&lt;/P&gt;</description>
      <pubDate>Mon, 20 Apr 2020 14:53:33 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/need-to-calculate-the-numeric-sum-values-from-multiple-fields/m-p/1358578#M15504</guid>
      <dc:creator>Akash Gurram1</dc:creator>
      <dc:date>2020-04-20T14:53:33Z</dc:date>
    </item>
  </channel>
</rss>

