Display error message when user create a more than one planning task
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2023 06:36 AM
Hi Team,
Display error message, when user create more than one planning task on the change request.
Regards,
Manasa
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2023 07:16 AM
you can use before insert BR on change_task and check if for this CHG there already exists a planning task.
if yes then show error message and abort the business rule
what script did you start with and where are you stuck?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2023 04:11 AM
Hi Ankur,
Please provide the step-by-step process for the above requirement.
Regards,
Manasa.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2023 04:22 AM
I would suggest to start the script from your side as it will be learning for you as well.
if you are stuck community members can help you.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2023 04:26 AM
Hello @Manasa Allu ,
Assuming you have some Planning Task table associated with change request. If its Change task just change table name in script.
Write Before BR on Planning Task/ Change Task as below
// Query the Planning Task table to count existing planning tasks related to this Change Request
var planningTaskCount = new GlideAggregate('planning_task'); // if its change task replace name accordingly
planningTaskCount.addQuery('change_request', current.sys_id); // there should be filed on table poninting to CR
planningTaskCount.addAggregate('COUNT');
planningTaskCount.query();
var numberOfPlanningTasks = 0;
if (planningTaskCount.next()) {
numberOfPlanningTasks = parseInt(planningTaskCount.getAggregate('COUNT'));
}
// Check if there's already more than one planning task related to the change request
if (numberOfPlanningTasks > 1) {
// Display an error message and prevent the creation of the new planning task
gs.addErrorMessage('Only one planning task is allowed per Change Request.');
current.setAbortAction(true);
}
If you are not aware about before business rule check it What is Before Business Rule in ServiceNow
Kindly mark correct and helpful if applicable