- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-28-2023 04:31 AM
When opening a Ctask or editing planned and actual Ctask dates, check Ctask values against CR Planned start and end dates.
If a Ctask planned start or actual start date is prior to the related CR planned start date, display a Pop-up with a warning that the start date is prior to the CR planned start date.
If a Ctask planned end or actual end date is after the related CR planned end date, display a Pop-up with a warning that the end date is after the CR planned end date and that a time extension approval will be required from Change Management.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-28-2023 04:54 AM
Hi @Tippireddy Venk
To achieve the described functionality in ServiceNow, you can use Business Rules and Client Scripts
Create a Business Rule:
- Navigate to "System Definition" -> "Business Rules" in the application navigator.
- Click on "New" to create a new business rule.
- Name your business rule, e.g., "CheckCtaskDatesAgainstCRDates".
- Set the "Table" to "Change Task [change_task]" or your corresponding table.
- Set the "When to run" to "Before" and "Insert", "Update", and "Delete".
- Write a script to check the conditions and display a warning message
(function executeRule(current, previous /*null when async*/) {
// Check if the planned start date is prior to CR planned start date
if (current.planned_start < current.change_request.planned_start) {
gs.addErrorMessage("Warning: Ctask start date is prior to CR planned start date.");
} // Check if the planned end date is after CR planned end date
if (current.planned_end > current.change_request.planned_end) {
gs.addErrorMessage("Warning: Ctask end date is after CR planned end date. Time extension approval will be required from Change Management.");
}
})(current, previous);2. Create a Client Script:
- Navigate to "System Definition" -> "Client Scripts" in the application navigator.
- Click on "New" to create a new client script.
- Name your client script, e.g., "CheckCtaskDatesClientScript".
- Set the "Table" to "Change Task [change_task]" or your corresponding table.
- Set the "Type" to "OnChange" for both planned start and planned end fields.
- Write a script to check the conditions and display a warning pop-up.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
// Check if the planned start date is prior to CR planned start date
if (newValue < g_form.getValue('change_request.planned_start')) {
alert("Warning: Ctask start date is prior to CR planned start date.");
g_form.setValue('planned_start', oldValue); // Revert to the old value
}// Check if the planned end date is after CR planned end date
Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
if (newValue > g_form.getValue('change_request.planned_end')) {
alert("Warning: Ctask end date is after CR planned end date. Time extension approval will be required from Change Management.");
g_form.setValue('planned_end', oldValue); // Revert to the old value
}
}
I hope this will help you to get your requirement.
Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-28-2023 04:48 AM
You can always use glideajax to be able to use server side script to fetch and compare the field values across different tables
Aman Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-28-2023 04:54 AM
Hi @Tippireddy Venk
To achieve the described functionality in ServiceNow, you can use Business Rules and Client Scripts
Create a Business Rule:
- Navigate to "System Definition" -> "Business Rules" in the application navigator.
- Click on "New" to create a new business rule.
- Name your business rule, e.g., "CheckCtaskDatesAgainstCRDates".
- Set the "Table" to "Change Task [change_task]" or your corresponding table.
- Set the "When to run" to "Before" and "Insert", "Update", and "Delete".
- Write a script to check the conditions and display a warning message
(function executeRule(current, previous /*null when async*/) {
// Check if the planned start date is prior to CR planned start date
if (current.planned_start < current.change_request.planned_start) {
gs.addErrorMessage("Warning: Ctask start date is prior to CR planned start date.");
} // Check if the planned end date is after CR planned end date
if (current.planned_end > current.change_request.planned_end) {
gs.addErrorMessage("Warning: Ctask end date is after CR planned end date. Time extension approval will be required from Change Management.");
}
})(current, previous);2. Create a Client Script:
- Navigate to "System Definition" -> "Client Scripts" in the application navigator.
- Click on "New" to create a new client script.
- Name your client script, e.g., "CheckCtaskDatesClientScript".
- Set the "Table" to "Change Task [change_task]" or your corresponding table.
- Set the "Type" to "OnChange" for both planned start and planned end fields.
- Write a script to check the conditions and display a warning pop-up.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
// Check if the planned start date is prior to CR planned start date
if (newValue < g_form.getValue('change_request.planned_start')) {
alert("Warning: Ctask start date is prior to CR planned start date.");
g_form.setValue('planned_start', oldValue); // Revert to the old value
}// Check if the planned end date is after CR planned end date
Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
if (newValue > g_form.getValue('change_request.planned_end')) {
alert("Warning: Ctask end date is after CR planned end date. Time extension approval will be required from Change Management.");
g_form.setValue('planned_end', oldValue); // Revert to the old value
}
}
I hope this will help you to get your requirement.
Thanks