
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-01-2017 11:34 AM
Hello SN Comm,
Looking for some scripting help (suggestions on which to use).
I was thinking either using the Calculated script within the third field OR I believe I have read that a Business Rule would be best.
Here is the story:
I need to create calculated fields to sum the scores into the two totals
For example sake this is what I have created so far within our Test Instance:
Drop-down field ALPHA: choices are:
- 1. "Red — 1 point"
- 2. "Blue — 3 points"
- 3. "Green — 5 points"
Drop-down field BETA: choices are:
- 1. "Leather — 5 points"
- 2. "Vinyl — 2 points"
"Nylon — 1 point"
Calculated field GAMMA: Sum the point values of the two fields. If I pick Green Nylon, the result is 6
I have created a quick script however all it does is bring the two value numbers assigned to each color and put them together. So if I pick Green and Nylon, Gamma shows 51.
here is my current script: mind you, this script I am using as a calculation from the Gamma field..
current.u_gamma = current.u_alpha + current.u_beta;
Any help on best way to do this (again I believe it probably should be a business rule) - and help with how the script should be.
Thanks in advance!!
-Rob
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-01-2017 11:42 AM
The reason for that is it takes its as string,
try:-
current.u_gamma = parseInt(current.u_alpha) + parseInt(current.u_beta);
you may try the if condition for various combinations
var val =0;
if (current.u_alpha == '1' && current.u_beta == '5' )
val = 6
if (current.u_alpha == '1' && current.u_beta == '2' )
val = 3;
:
:
& so on...

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-10-2017 06:07 AM
So at first, both Alpha and Beta were created as a String and Gamma was an Integer. Not sure if that matters at all. (Today I deleted those and made new ones with a Type of Integer) - (or should I remake them all to be a different TYPE? - Currency or something else?)
First I have a question, are you saying to take out the Gamma script you gave me earlier and replace it with this new one you tested?
Alpha and Beta did not have any 'value' per say. I created choices that users could select from, and wanted Gamma to return the total value from those two selections.
This morning, Both Alpha and Beta are Type Integers and each have three choices that I can select from with a dollar amount value. within their values, i put a dollar amount (Example: 45.00).. but then I was getting an error from the Case form saying 'invalid integer'. So I went back to the values of the choices and took out the decimal, but now Gamma isn't returning anything for me.
Sorry I keep running into issues with what you are giving me for help - should the TYPE for all three fields be Integers or should I make them something else?
I appreciate your help with all of this - and thanks again in advance with further help!
-Rob

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-10-2017 08:23 AM
Hello Shiliaditya,
Can you go with this current scenario?
I started from scratch...
Alpha / Beta / Gamma - are all now new fields as Currency Type.
If I enter in a price for both Alpha and Beta, I would like Gamma to return the Sum. Would we be able to use any of the above you have shown me, or would this be something different? Also, can Gamma still have a script to do the job in the Calculation Script - or would a Business Rule / Client Script be better?
Thanks,
-Rob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-10-2017 08:22 AM
in the code below there are 3 variables
one currency, the other string and fourth the integer..
hope this code gets what you need..
var number1 = '$12,333.56'; //currency
var number2 = '5777'; // string
var number3 = 3 //integer
//stripping currency of $ and,
number1 = number1.replace('$','');
number1 = number1.replace(',','');
//gs.print(number1); //op: 12333.56
//now adding all the variables.. number4 has the sum
var number4 = parseFloat(number1) + parseFloat(number2) + parseFloat(number3);
//gs.print(number4); //op : 18113.559999999998
//Rounding up to two decimal places
number4 =number4.toFixed(2);
//gs.print(number4); //op: 18113.56
//now making it into currency ie. having coma, if you want
number4 = (number4 + "").replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,");
//gs.print(number4); //op : 18,113.56
//now adding $
number4 = '$'+number4;
//gs.print(number4); //op : $18,113.56

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-10-2017 08:34 AM
Shiladitya,
With having all three fields as Currency Type - if we do a Calculation Script as: current.u_gamma = parseFloat(current.u_alpha) + parseFloat(current.u_beta);
The correct Sum shows in Gamma, with coma and decimal in the right places..
I am now 100% all set! You have helped out big time! The more I see and do, the more I learn and understand.
I got it to work - Thank you so much!!
-Rob