
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-11-2016 01:36 PM
Hi everyone, within the form I created I have a date field called "Expected Completion Date". Whenever the value of the field changes to any other value I would like the next field "Expected Completion Date Change Reason" to become a required field. So basically in order to change the date field you need to provide a reason. Does anyone know how this can be done, possible using a script?
Thanks,
Edwin
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-12-2016 06:31 AM
Try this
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
if(g_form.isNewRecord() && newValue!=''){
g_form.setMandatory('u_start_date', false);
}
return;
}
if(oldValue != newValue)
{
g_form.setMandatory('u_start_date', true); //Here replace u_start_date with exact field column name
}
else
{
g_form.setMandatory('u_start_date', false); //Here replace u_start_date with exact field column name
}
//Type appropriate comment here, and begin script below
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-12-2016 06:42 AM
Thank you

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-11-2016 02:01 PM
Hi Edwin,
Looks like date filter is not applicable in UI policy. Please create a OnChange Client script on "Expected Completion Date" field with below script. Please modify field column names as per your req.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
if(oldValue != newValue)
{
g_form.setMandatory('u_start_date', true); //Here replace u_start_date with exact field column name
}
else
{
g_form.setMandatory('u_start_date', false); //Here replace u_start_date with exact field column name
}
//Type appropriate comment here, and begin script below
}
Client Scripts - ServiceNow Wiki

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-11-2016 06:56 PM
Hi Edwin,
Is the issue resolved now?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-12-2016 06:24 AM
The script works as intended, but I need a condition. When the field is populated for the first time or there is no previous value then do NOT require the next field