client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2024 02:49 AM
Hi
I have written this below client script . I have a checkbox field if that is checked a reference field is becoming visible and mandatory so from that field record it should fetch title and detail and autopopulate in present form. but in title and detail I am getting value as undefined. Please correct my code.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2024 08:10 AM
@Vedavalli Please update your script as follows and see if it works.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
alert('hi');
var pickSelected = g_form.getValue('pick_from_library');
if (pickSelected == 'true') {
alert('hlo');
var toDo = g_form.getReference('to_do',callBack);
}
else{
g_form.clearValue('title');
g_form.clearValue('detail');
}
//Type appropriate comment here, and begin script below
function callBack(toDo){
alert(toDo);
if (toDo) {
alert(toDo.title);
g_form.setValue('title', toDo.title);
g_form.setValue('detail', toDo.detail);
} else {
alert('bye');
g_form.clearValue('title');
g_form.clearValue('detail');
}
}
}
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2024 08:21 AM - edited 03-12-2024 08:21 AM
Hi @Vedavalli
Try the below, I just updated line 8 and replaced getValue() with getReference() due to the type of field. Let me know how you get on.
if (isLoading || newValue === '') {
return;
}
alert('hi');
var pickSelected = g_form.getValue('pick_from_library');
if (pickSelected == 'true') {
alert('hlo');
var toDo = g_form.getReference('to_do').value;
alert(toDo);
if (toDo) {
alert(toDo.title);
g_form.setValue('title', toDo.title);
g_form.setValue('detail', toDo.detail);
} else {
alert('bye');
g_form.clearValue('title');
g_form.clearValue('detail');
}
}
else{
g_form.clearValue('title');
g_form.clearValue('detail');
}
Please mark as helpful or if its resolved the issue, CORRECT!