- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2024 07:53 AM
Hi,
I'm trying to create a Client Script that will set the value for a custom field based off of a value from another custom field.
Here is how it should work:
If u_essay_1_score is 5, then u_essay_1_points should display 33
If u_essay_1_score is 4, then u_essay_1_points should display 27
If u_essay_1_score is 3, then u_essay_1_points should display 21
If u_essay_1_score is 2, then u_essay_1_points should display 13
If u_essay_1_score is 1, then u_essay_1_points should display 5
Any help with this script would be greatly appreciated!
Thank you, Valerie
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2024 08:26 AM
The following client script should work to map the value.
var dataMap = {
"5": "33",
"4": "27",
"3": "21",
"2": "13",
"1": "5"
}
var value = g_form.getValue("u_essay_1_score");
g_form.setValue("u_essay_1_points", dataMap[value])
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2024 08:28 AM - edited 05-31-2024 08:31 AM
Hi @Valerie24
You can try the below Script:
On change client script (field : u_essay_1_score) and change the field names based on your requirement
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var score = g_form.getValue('essay_1_score');
alert(score);
if (score == '5') {
g_form.setValue('essay_1_points', '33');
} else if (score == '4') {
g_form.setValue('essay_1_points', '27');
} else if (score == '3') {
g_form.setValue('essay_1_points', '21');
} else if (score == '2') {
g_form.setValue('essay_1_points', '13');
} else if (score == '1') {
g_form.setValue('essay_1_points', '1');
}
//Type appropriate comment here, and begin script below
}
Thanks and Regards
Sai Venkatesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2024 08:46 AM
Hi @Valerie24 ,
You can achieve it by using onChange client script. You can choose the client script type as "onChange" and Field name as "Essay score". Copy paste the below script.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Type appropriate comment here, and begin script below
switch (newValue) {
case '1':
g_form.setValue('u_essay_points', '53');
break;
case '2':
g_form.setValue('u_essay_points', '54');
break;
default:
g_form.setValue('u_essay_points', '55');
}
}
When ever you change the Essay score, the Essay points will auto populate. Please let me know if you've any questions.
Please mark the answer helpful, if it helped you accordingly.
Regards,
Hari

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2024 08:26 AM
The following client script should work to map the value.
var dataMap = {
"5": "33",
"4": "27",
"3": "21",
"2": "13",
"1": "5"
}
var value = g_form.getValue("u_essay_1_score");
g_form.setValue("u_essay_1_points", dataMap[value])
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2024 08:28 AM - edited 05-31-2024 08:31 AM
Hi @Valerie24
You can try the below Script:
On change client script (field : u_essay_1_score) and change the field names based on your requirement
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var score = g_form.getValue('essay_1_score');
alert(score);
if (score == '5') {
g_form.setValue('essay_1_points', '33');
} else if (score == '4') {
g_form.setValue('essay_1_points', '27');
} else if (score == '3') {
g_form.setValue('essay_1_points', '21');
} else if (score == '2') {
g_form.setValue('essay_1_points', '13');
} else if (score == '1') {
g_form.setValue('essay_1_points', '1');
}
//Type appropriate comment here, and begin script below
}
Thanks and Regards
Sai Venkatesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2024 08:46 AM
Hi @Valerie24 ,
You can achieve it by using onChange client script. You can choose the client script type as "onChange" and Field name as "Essay score". Copy paste the below script.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Type appropriate comment here, and begin script below
switch (newValue) {
case '1':
g_form.setValue('u_essay_points', '53');
break;
case '2':
g_form.setValue('u_essay_points', '54');
break;
default:
g_form.setValue('u_essay_points', '55');
}
}
When ever you change the Essay score, the Essay points will auto populate. Please let me know if you've any questions.
Please mark the answer helpful, if it helped you accordingly.
Regards,
Hari