Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Set mandatory using on change client script

Sahar_Kaizer
Tera Contributor

Hi,

I am trying to write on change client script, so that if "state" field changes directly from "new" (1)  to any other status except "in progress" (2), assigned to field will be mandatory on SOW.

 

I tried this:

Sahar_Kaizer_0-1704634820664.png

 

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


   if (oldValue == 1 && newValue != 2) {
        g_form.setMandatory('assigned_to', true);
    }else {
        g_form.setMandatory('assigned_to', false);
    }
}
 but it doesnt work...
I would appreciate any help.
 
Thanks, 
Sahar.
8 REPLIES 8

Clara Lemos
Mega Sage

Hi @Sahar_Kaizer ,

 

Try making the following modification in your script:

 

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

    if (oldValue == '1' && newValue != '2') {
        g_form.setMandatory('assigned_to', true);
    } else {
        g_form.setMandatory('assigned_to', false);
    }
}

If that helps please mark my answer as correct / helpful!
And if further help is needed please let me know

Cheers

Thanks but it didnt work

 

Narsing1
Mega Sage

Try like this

if (oldValue.toString().indexOf("1") > -1 && newValue.toString().indexOf("2") < 0) {
            g_form.setMandatory('assigned_to', true);
        } else {
            g_form.setMandatory('assigned_to', false);
        }

Thanks,

Narsing

also doesnt work