help with a client script

Jen11
Tera Expert

Hello, 

I need help with an onChange client script on the TASK level. Once a Task has been created for a certain catalog item, when the State for the TASK changes to 'Closed Complete' I would like a certain field to be mandatory.  Can someone help me with that please? 

8 REPLIES 8

SAI VENKATESH
Tera Sage
Tera Sage

Hi @Jen11 

 

you can write an ui policy on sc task on the catalog item whenever state is closed complete you can make field mandatory.

 

Thanks and Regards 

Sia Venkatesh 

Swapna Abburi
Mega Sage
Mega Sage

Hi @Jen11 

If it is a field on sc_task table, then you can write UI policy to make the field mandatory when catalog item and state conditions matches.

If you are trying to make a catalog variable as mandatory then you may write on-change client script on state change. Sample script:

if (g_form.getValue("cat_item") == "catalog item sys_id") {
        g_form.setReadOnly("VARIABLE_NAME", false);
        g_form.setMandatory("VARIABLE_NAME", true);
}

Ankur Bawiskar
Tera Patron
Tera Patron

@Jen11 

it's a field or it's a variable which needs to be mandatory?

If it's a variable then you will have to write onChange client script on State field on sc_task

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

    if (g_form.getValue('state') == '3' && g_form.getValue('variables.variableName') == '') {
        g_form.setMandatory('variables.variableName', true);
    }

}

You should also use onSubmit client script since user can click "Close Task" button to move task to close complete

function onSubmit() {

    if (g_form.getValue('state') == '3' && g_form.getValue('variables.variableName') == '') {
        g_form.setMandatory('variables.variableName', true);
        return false;
    }

}

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

how do i specify for a certain catalog item only?