How to check number of Ctask created for the Change request.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2025 05:04 AM
Hi,
The requirement is to check the number of Ctask and if more than one ctask is created for a change request, then the implementation start and end date should be empty.
Please let me know if there a way to check.
Thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2025 05:09 AM
you can query change_task and get the count
Where should this be written? Is this BR on change_request?
If yes then use this
var ga = new GlideAggregate('change_task');
ga.addQuery('change_request', current.sys_id);
ga.addAggregate('COUNT');
ga.query();
if (ga.next()) {
var count = ga.getAggregate('COUNT');
if (count > 1) {
// your logic
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2025 06:55 PM
Hope you are doing good.
Did my reply answer your question?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2025 09:47 PM
Hope you are doing good.
Did my reply answer your question?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2025 06:28 AM
@Tamilvanan T You can create an onAfter Insert business rule on the change_task table as follows.
(function executeRule(current, previous /*null when async*/) {
// Get the associated Change Request
var changeRequest = new GlideRecord('change_request');
if (changeRequest.get(current.change_request)) {
// Count the number of associated Change Tasks
var ctaskCount = new GlideAggregate('change_task');
ctaskCount.addQuery('change_request', current.change_request);
ctaskCount.addAggregate('COUNT');
ctaskCount.query();
if (ctaskCount.next() && ctaskCount.getAggregate('COUNT') > 1) {
// Clear Implementation Start and End Dates if more than one CTask exists
changeRequest.start_date = '';
changeRequest.end_date = '';
changeRequest.update();
}
}
})(current, previous);