If checkbox is checked auto populate reference filed

Bidduam
Tera Guru

For a catalog item I'm creating I need to populate a reference field if checkbox is checked, with the current user.

 

Checkbox variable field:

checkbox_1

 

Reference field on sys_user table:

name_field

 

If checkbox_1 = true then name_field = current users name

 

I figure this would require a Catalog Client Script?

Not sure how to write it - if anyone is able to assist please?

1 ACCEPTED SOLUTION

Ok thank you @Anirudh Pathak I've tried it and hasn't worked unfortunately

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }

    //Type appropriate comment here, and begin script below
    var check = g_form.getValue('checkbox_1');
    if (check == true) {
        g_form.setValue('name_field', g_user.userID);
    } else {
        g_form.clearValue('name_field');
    }
}

 

 

View solution in original post

9 REPLIES 9

Astik Thombare
Tera Sage

Hi @Bidduam ,

 

You need to write a onchange

 

Thanks,

Astik

Pratiksha
Mega Sage
Mega Sage

you can learn catalog client script here. 

https://youtu.be/zkWTybCed34?si=dEfbautm7-XOziAA

Anirudh Pathak
Mega Sage

Hi @Bidduam ,

You can create an "onchange" client script on checkbox_1 variable - 

 if (newValue == 'true') {
        g_form.setValue('name_field', g_user.userID);
} else {
        g_form.clearValue('name_field');
    }

Ok thank you @Anirudh Pathak I've tried it and hasn't worked unfortunately

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }

    //Type appropriate comment here, and begin script below
    var check = g_form.getValue('checkbox_1');
    if (check == true) {
        g_form.setValue('name_field', g_user.userID);
    } else {
        g_form.clearValue('name_field');
    }
}