
- 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-09-2017 11:20 AM
Thanks for the reply Shiladitya,
However, I think I am blanking on how it should be scripted for the calculated script.
Currently I have:
current.u_gamma = parseInt(current.u_alpha) + parseInt(current.u_beta);
Would it be something like this:
function parseCurrency( num ) {
return parseFloat( num.replace( /,/g, '') );
}
alert( parseCurrency(u_alpha) + parseCurrency(u_beta) );
I feel like I am completely wrong - able to help on how this should actually be written?
thanks,
-Rob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-09-2017 11:33 AM
current.u_gamma = parseInt(current.u_alpha) + parseInt(current.u_beta);
alert(current.u_gamma);
var number1 = current.u_alpha;
var number2 = current.u_beta;
function parseCurrency( num ) {
return parseFloat( num.replace( /,/g, '') );
}
alert( parseCurrency(number1) + parseCurrency(number2)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-09-2017 01:28 PM
Thanks for your reply Shiladitya,
Unfortunately, that script is not displaying any value at all within the Gamma field.
Not sure what I can move around from what you provided to try and get to work properly.
Thanks,
-Rob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-09-2017 08:53 PM
what value does
current.u_alpha and urrent.u_beta
have ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-09-2017 11:26 PM
I have tested the following code in scripts-background
and its working...
var number1 = '12,33.90';
var number2 = '7,687.06';
var number = parseFloat(number1.replace(',','')) + parseFloat(number2.replace(',',''))
gs.print( number.toFixed(2)) ; //two decimal places
//////////////////
result -> *** Script: 8920.96
if the var has & then replace it e.g. number1.replace('$','');
and later add $ e.g. number = '$'+number;