client side autopopulate

shivaadapa
Tera Expert

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.

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.getDisplayBox('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');

    }

2 REPLIES 2

Prataps135
Mega Sage

Hello Shivaadapa,

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('hello');
        var toDo = g_form.getDisplayBox('to_do').value;

        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');
    }
}

try this and let me know if it is working for you or not.

Harish KM
Kilo Patron
Kilo Patron

Hi @shivaadapa is the title and detail are single line variables? then use autopopulate feature on each variable, no need to script.

Regards
Harish