Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Detect Circular Reference in Task Dependencies

## Overview

This Script Include helps identify **circular dependencies** in task relationships within ServiceNow. Circular references can cause workflow issues, reporting errors, and logic failures in project management or task tracking modules.

## What It Does

- Traverses task dependencies recursively.
- Detects if a task is indirectly dependent on itself.
- Returns `true` if a circular reference is found, `false` otherwise.

## Use Case

Imagine Task A depends on Task B, and Task B depends on Task A. This creates a circular loop that can break automation or cause infinite recursion. This script helps prevent such configurations.


Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
var DependencyChecker = Class.create();
DependencyChecker.prototype = {
initialize: function() {},

hasCircularReference: function(taskId) {
var visited = {};
return this._check(taskId, visited);
},

_check: function(taskId, visited) {
if (visited[taskId]) return true;
visited[taskId] = true;

var gr = new GlideRecord('task_dependency');
gr.addQuery('dependent_task', taskId);
gr.query();

while (gr.next()) {
if (this._check(gr.task.toString(), visited)) return true;
}

return false;
},

type: 'DependencyChecker'
};
Loading