- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2021 08:49 AM
Hi,
I'm using client script to calculate the value of a+b and get total sum value in the single line text box. This script is not working for me. can you help me
I'm using 2 select box'es
a Select Box has option yes or no (Yes value as 10 ; No Value as 5)
b Select Box has option yes or no (Yes value as 10 ; No Value as 5)
I'm using C as a single line text box I need to get the score of what the user selects.
If Select Yes in A; Yes in B;
It should autopopulate C as 10
Client Script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
var xyz ='';
var X = g_form.getValue('a');
alert('a');
var Y = g_form.getValue('b');
var Z = g_form.getValue('c');
xyz = X+Y+Z;
g_form.setValue('score', xyz);
alert('xyz');
return;
}
}
Please Help!!
Thank you!!!
Solved! Go to Solution.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2021 12:09 AM
Hi
Finally Im here with an answer,
That is you have to write two Onchange client scripts() for two variables ie, var1,var2.
I have tried in my PDI its working as you expected.
Im posting the screenshots as well..
Let me know if you still facing difficulty..
Code:
Onchange()
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if (newValue != oldValue && newValue != '') {
var f1 = g_form.getValue('variable1');
var f2 = g_form.getValue('variable2');
if (f1 != '' && f2 != '') {
g_form.setValue('result', parseInt(f1) + parseInt(f2));
}
}
}
PFA:
Thanks,
Murthy
Murthy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2021 09:43 AM
Yeah, i verified and i gave the names as a, b,c
and also i made the changes i changed variable name from empty to a.
Now when i'm selecting options in A either as Yes or No it's giving me NaN

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2021 09:52 AM
Yes it will give you NaN because you select some value in a which can be parsed to Int.
But the fields b and c has value None which cannot be parsed to Int. so is your error.
Make sure you select B and C variables first if your client script is on A
Use this updated script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var X = g_form.getValue('variables.a');
var Y = g_form.getValue('variables.b');
var Z = g_form.getValue('variables.c');
var xyz = 0;
if (X != '') {
xyz += parseInt(X);
}
if (Y != '') {
xyz += parseInt(Y);
}
if (X != '') {
xyz += parseInt(Z);
}
g_form.setValue('variables.score', xyz);
alert(xyz);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2021 10:17 AM
yeah i tried this script but still no luck Mahesh.
First selected options in B and C and then A
it is now showing the value as 0 when i select either Yes or No in the Field A
Is it not taking the backend value of a,b,c?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2021 12:09 AM
Hi
Finally Im here with an answer,
That is you have to write two Onchange client scripts() for two variables ie, var1,var2.
I have tried in my PDI its working as you expected.
Im posting the screenshots as well..
Let me know if you still facing difficulty..
Code:
Onchange()
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if (newValue != oldValue && newValue != '') {
var f1 = g_form.getValue('variable1');
var f2 = g_form.getValue('variable2');
if (f1 != '' && f2 != '') {
g_form.setValue('result', parseInt(f1) + parseInt(f2));
}
}
}
PFA:
Thanks,
Murthy
Murthy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2021 07:48 AM
Thank you very much Murthy. It worked.