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,7 @@
# Count Related Incidents for a Problem Record (Business Rule)

Purpose
This Business Rule calculates and displays the **number of incidents** linked to a specific **Problem record** in ServiceNow.

Whenever a problem record is opened or updated, it counts all related incidents and shows the count as an informational message.

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@


(function executeRule(current, previous /*null when async*/) {

var problemSysId = current.sys_id;
var agg = new GlideAggregate('incident');
agg.addQuery('problem_id', problemSysId);
agg.addAggregate('COUNT');
agg.query();

if (agg.next()) {
var incidentCount = agg.getAggregate('COUNT');
gs.addInfoMessage('There are ' + incidentCount + ' incidents related to this problem.');
}

})(current, previous);
12 changes: 12 additions & 0 deletions Server-Side Components/Business Rules/DateDifference.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
(function executeRule(current, previous /*null when async*/) {

// Add your code here
if(current.u_termination_date.changes()){
var date1=current.u_current_date;
var date2=current.u_termination_date;

var res=onDemand1(date1,date2);
gs.addInfoMessage("Date Difference is :"+res);

}
})(current, previous);
14 changes: 14 additions & 0 deletions Server-Side Components/Business Rules/MyFolder/CreateProblem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
(function executeRule(current, previous /*null when async*/) {

// Add your code here
if(current.category == 'hardware'){
var gr=new GlideRecord('problem');
gr.initialize();
gr.short_description=current.short_description;
gr.category=current.category;
gr.impact=current.impact;
gr.urgency=current.urgency;
gr.insert();

}
})(current, previous);
2 changes: 2 additions & 0 deletions Server-Side Components/Business Rules/MyFolder/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This script is a ServiceNow Business Rule that automatically creates a Problem record whenever an Incident is created with the category set to "hardware".
It helps in ensuring that hardware-related incidents are tracked and analyzed properly through Problem Management.
16 changes: 16 additions & 0 deletions Server-Side Components/Business Rules/ProblemCount.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@


(function executeRule(current, previous /*null when async*/) {

var problemSysId = current.sys_id;
var agg = new GlideAggregate('incident');
agg.addQuery('problem_id', problemSysId);
agg.addAggregate('COUNT');
agg.query();

if (agg.next()) {
var incidentCount = agg.getAggregate('COUNT');
gs.addInfoMessage('There are ' + incidentCount + ' incidents related to this problem.');
}

})(current, previous);
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Filter Users by Department


This Script Include returns users whose department is the same as the currently logged-in user’s department.
It can be used to filter the Caller field or any user reference field to show only users from the same department.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
var getSameDeptUsers = Class.create();
getSameDeptUsers.prototype = {
initialize: function() {},
getSameDept: function() {
var user = gs.getUser().getDepartmentID();
var d = new GlideRecord('sys_user');
d.addQuery('department', user);
d.query();

var str = "";
while (d.next()) {
str = str + "," + d.sys_id;
}
return 'sys_idIN' + str;

},

type: 'getSameDeptUsers'
};
Loading