CMDB TASK assignment update if IT Application owner changes in Application table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-05-2025 10:07 AM
Hi All,
I have below requirement.
If the IT application owner of a business application changes, any tasks in the CMDB Data Management Task table (cmdb_data_management_task) where the old owner was in the Assigned to field, should be updated to the new owner ONLY if all the business applications in the CMDB Data Management Certification Task To Document related list with a status of Pending are also owned by the new owner.If there are different owner for those business Applications then no action should be taken.
if the IT application owner of a business application changes, any tasks in the CMDB Data Management Task table (cmdb_data_management_task) where the Assigned to field is blank, should be assigned to the new owner ONLY if all the business applications in the CMDB Data Management Certification Task To Document related list with a status of Pending are also owned by the new owner. If there are different owner for those business Applications then no action should be taken.
Tables & field information:
CMDB Data Management Task (backend name:cmdb_data_management_task) --->Number,assigned to field
CMDB Data Management Certification Tasks to Documents(sn_cmdb_ws_dm_certification_task_to_document) -Application are stored in Document ID field(colum name is CI and type of the field is Document ID),CMDB task field stores task number(reference to CMDB data mangement task)
Hereby I am also providing the script which i have written.Could you please check and confirm if I am missing something as this is not working.
Below is Businerule(After,Update).
(function executeRule(current, previous /*null when async*/ ) {
if (!current.it_application_owner.changes())
return;
var oldOwner = previous.it_application_owner;
var newOwner = current.it_application_owner;
if (oldOwner == newOwner || !newOwner) {
return;
}
// Find all task to document records linked to this Business App with pending status
var certTaskGR = new GlideRecord('sn_cmdb_ws_dm_certification_task_to_document');
certTaskGR.addQuery('ci', current.sys_id);
certTaskGR.addQuery('status', 'Pending');
certTaskGR.query();
var taskIDs = new Set();
while (certTaskGR.next()) {
taskIDs.add(certTaskGR.cmdb_data_management_task.toString());
}
//Loop over each affected task
taskIDs.forEach(function(taskId) {
var allSameOwner = true;
// Get all related Business Applications for this task with pending status
var checkGR = new GlideRecord('sn_cmdb_ws_dm_certification_task_to_document');
checkGR.addQuery('cmdb_data_management_task', taskId);
checkGR.addQuery('status', 'Pending');
checkGR.query();
while (checkGR.next()) {
var relatedApp = checkGR.document_id.getRefRecord();
if (!relatedApp || relatedApp.it_application_owner != newOwner.toString()) {
allSameOwner = false;
break;
}
}
//if all apps have the same new owner update the task
if (allSameOwner) {
var taskGR = new GlideRecord('cmdb_data_management_task');
if (taskGR.get(taskId)) {
if (!taskGR.assigned_to || taskGR.assigned_to == oldOwner) {
taskGR.assigned_to = newOwner;
taskGR.update();
}
}
}
});
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-05-2025 10:25 AM
Hi @_bhishek ,
try this
(function executeRule(current, previous /*null when async*/ ) {
var oldOwner = previous.getValue('it_application_owner');
var newOwner = current.getValue('it_application_owner');
if (!current.it_application_owner.changes() || oldOwner == newOwner || !newOwner)
return;
var currentSysID = current.getValue('sys_id');
// Find all task to document records linked to this Business App with pending status
var certTaskGR = new GlideRecord('sn_cmdb_ws_dm_certification_task_to_document');
certTaskGR.addQuery('ci', currentSysID);
certTaskGR.addQuery('status', 'pending'); //Pending to pending
certTaskGR.query();
var taskIDs = [];
while (certTaskGR.next()) {
if (taskIDs.indexOf(certTaskGR.getValue('cmdb_data_management_task')) > -1)
taskIDs.push(certTaskGR.getValue('cmdb_data_management_task'));
}
//Loop over each affected task
taskIDs.forEach(function(taskId) {
var allSameOwner = true;
// Get all related Business Applications for this task with pending status
var checkGR = new GlideRecord('sn_cmdb_ws_dm_certification_task_to_document');
checkGR.addQuery('cmdb_data_management_task', taskId);
checkGR.addQuery('status', 'pending'); //Pending to pending
checkGR.query();
while (checkGR.next()) {
var relatedApp = new global.GlideRecordUtil().getGR(checkGR.getValue('table'), checkGR.getValue('ci'));
if (!relatedApp.isValidRecord() || relatedApp.getValue('it_application_owner') != newOwner) {
allSameOwner = false;
break;
}
}
//if all apps have the same new owner update the task
if (allSameOwner) {
var taskGR = new GlideRecord('cmdb_data_management_task');
if (taskGR.get(taskId)) {
if (!taskGR.getValue('assigned_to') || taskGR.getValue('assigned_to') == oldOwner) {
taskGR.setValue('assigned_to', newOwner);
taskGR.update();
}
}
}
});
})(current, previous);
if still not working try putting try catch or adding logs and
Please mark my answer as helpful/correct if it resolves your query.
Regards,
Chaitanya