On Load client script is not working to make checkbox true if another date field is not empty.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2024 12:02 AM
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 -
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2024 12:20 AM - edited 06-09-2024 12:24 AM
Hi @abhaysingh98 ,
Please try the below:
function onLoad() {
var dateFieldValue = g_form.getValue('u_due_date_2');
if (dateFieldValue != null || dateFieldValue != '') {
g_form.setValue('u_account_expiry', true);
}
}
Please hit like and mark my response as correct if that helps.
Mark this as Helpful / Accept the Solution if this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2024 12:34 AM
hi @SN_Learn
I tried this code also but it is not working properly for me checkbox is always true no matter if the date field is empty or not.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2024 01:08 AM
Hi @abhaysingh98 ,
Try the updated code:
function onLoad() {
var dateFieldValue = g_form.getValue('u_due_date_2');
if (dateFieldValue) {
g_form.setValue('u_account_expiry', false);
} else {
g_form.setValue('u_account_expiry', true);
}
}
Please hit like and mark my response as correct if that helps.
Mark this as Helpful / Accept the Solution if this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2024 12:49 AM
Hi @abhaysingh98,
Why don't you create UI Policy for this. There is condition field and apply action accordingly. Also check whether it is checked in variable itself.
Please accept my solution if it resolves your issue and thumps 👍 up
Thanks
Jitendra