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 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

@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  ||  10x 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