The CreatorCon Call for Content is officially open! Get started here.

Need help with Change Task client script mandatory field

alhicks
Tera Guru

The script below is making the field mandatory but once a value is entered and we hit update, it's still prompting for the mandatory field.   I've got this setup as a submit but thinking maybe it should be onChange.   Maybe when the state changes or the Title.   We have another script prompting and based on the answer, we're changing the Title to one of the below.

function onSubmit() {

    //Type appropriate comment here, and begin script below

   

function onChange(control, oldValue, newValue, isLoading, isTemplate) {

    if (isLoading || newValue === '') {

          return;

    }  

     

var action = g_form.getActionName();        

task_state = g_form.getValue('state');

task_sd = g_form.getValue('short_description');

task_assignment = g_form.getValue('assignment_group');

     

if(((task_sd=="Delete - Program Request - Release DB2")

|| (task_sd=="Delete - Program Request - Release DB2 & Disable CICS")

|| (task_sd=="Delete - Program Request - Disable CICS"))

&& ((task_assignment =='7a8232270a0a3c1f01cae985bf9ffdcf') && (task_state=='3'))){      

var remove_program =g_form.getValue('u_remove_program_from_db2_or_cics');  

if (remove_program == "");

alert('Remove program from DB2 or CICS is mandatory');

     

g_form.setMandatory('u_remove_program_from_db2_or_cics', true);      

} else

      {

  g_form.setMandatory('u_remove_program_from_db2_or_cics',false);

}

}

}

1 ACCEPTED SOLUTION

Wanted to thank everyone for their help.   I decided to get rid of the client scripts and just add a couple new fields to the change task form, and use UI Policy's to show and make them mandatory.   Then changed the workflow to use scratchpad to capture the information on the change task to auto assign the task.   Much cleaner....thanks again.


View solution in original post

7 REPLIES 7

Wanted to thank everyone for their help.   I decided to get rid of the client scripts and just add a couple new fields to the change task form, and use UI Policy's to show and make them mandatory.   Then changed the workflow to use scratchpad to capture the information on the change task to auto assign the task.   Much cleaner....thanks again.


Michael Ritchie
ServiceNow Employee
ServiceNow Employee

If the state or assignment changes before the user clicks submit, that would definitely affect this script since its looking for a specific assignment group and state along with the description. If you can explain a little more about your requirement and maybe include a screenshot, I'd be happy to help you further.


arnabwa
Giga Guru

Hi Andrea,



If you are looking for an onSubmit client script, this should be your code :



function onSubmit() {



var task_state = g_form.getValue('state');


var task_sd = g_form.getValue('short_description');


var task_assignment = g_form.getValue('assignment_group');



if(((task_sd=="Delete - Program Request - Release DB2")


|| (task_sd=="Delete - Program Request - Release DB2 & Disable CICS")


|| (task_sd=="Delete - Program Request - Disable CICS"))


&& ((task_assignment =='7a8232270a0a3c1f01cae985bf9ffdcf') && (task_state=='3')))


{


var remove_program =g_form.getValue('u_remove_program_from_db2_or_cics');


if (g_form.getValue('u_remove_program_from_db2_or_cics')== '')


{


g_form.setMandatory('u_remove_program_from_db2_or_cics', true);


alert('Remove program from DB2 or CICS is mandatory');


}


}


}



This will do the work. Please check for the braces if they are balanced or not.



Thanks,


Arnab