On Load client script is not working to make checkbox true if another date field is not empty.

abhaysingh98
Tera Contributor

Hi All,

I am new to ServiceNow and facing an issue, I have written an on load client script to make checkbox true if other date field is not empty.

As per my understanding my code is correct but is is not executing.

 

ON Load Script -

 

function onLoad() {
    var dateFieldValue = g_form.getValue('u_due_date_2');
   
    if(dateFieldValue != '') {
        g_form.setValue('u_account_expiry', true);
    }

}
17 REPLIES 17

@Jitendra Diwak1 yes by saving the form we can save our data in backend and this will update the form but it will not work if both assignment group and assign to is filled then what to do?

I think running a scheduled job will work in this case so that it will automatically save the record.

Hi @abhaysingh98,

 

It will work in same manner. you do not need to run any schedule job. to perform the database operation, you need to save the data.

 

Please accept my solution if it resolves your issue and thumps up

 

Thanks

Jitendra

Please accept my solution if it works for and thumps up.

Anand Kumar P
Giga Patron
Giga Patron

Hi @abhaysingh98 ,

I tried in my pdi working as expected with below script

AnandKumarP_0-1718003602454.png

 

function onLoad() {
    var dateFieldValue = g_form.getValue('u_glide_date_field');
  alert(dateFieldValue);
  if(dateFieldValue == null || dateFieldValue == ''){
        g_form.setValue('u_check_box', false);
		alert('FALSE');
    }
    else if (dateFieldValue != null || dateFieldValue != '') {
        g_form.setValue('u_check_box', true);
		alert('True');
    } 

}

AnandKumarP_1-1718003625409.png

Mark it as helpful and solution proposed if it serves your purpose.
Thanks,
Anand

 

@Anand Kumar P have you checked in XML if this value of checkbox is saved as true or not?

@abhaysingh98 you are writing script on client side, xml it will show the data which is saved in the database not the onload value of the checkbox.

 

Thanks,

Anand