when one reference field is empty the other reference field should be empty. how can we achieve it?

sariksorte
Tera Contributor

when one reference field is empty the other reference field should be empty. how can we achieve it?

2 REPLIES 2

Sandeep Rajput
Tera Patron
Tera Patron

@sariksorte You can write an onChange client script on the first reference field as follows.

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

    // If the reference field is cleared, clear the dependent field
    if (!newValue) {
        g_form.clearValue('u_other_reference_field');//clear other reference field
    }
}

 

Ankur Bawiskar
Tera Patron
Tera Patron

@sariksorte 

you can use onChange client script on 1st field and empty the 2nd one

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading) {
        return;
    }

    // If the reference field is cleared, clear the dependent field
    if (newValue == '') {
        g_form.clearValue('2ndField');
    }
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader