set assigned to mandatory when state changes

Shir Sharvit
Tera Contributor

I need to write on change client script that if state field Changes directly from "new" (1)  to any other status except "in progress" (2), assigned to field  should be mandatory.

 

I tried this:

ShirSharvit_0-1704629078459.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);
    }
}
 
 

 

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

@Shir Sharvit 

so the above script is not working fine?

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

no it doesnt 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