
- 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-11-2016 01:38 PM
Hi Edwin,
This is simple. You can create a UI policy and trigger it only when i.e Expected completion date is changed then make Expected completed date change reason to mandatory.
Please refer below link for more info.
http://wiki.servicenow.com/index.php?title=Creating_a_UI_Policy

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-11-2016 01:41 PM
Write an onChnage client script on the Expected completion date field and put this script in there
g_form.setMandatory("your field name goes here",true);

- 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

- 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
}