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,14 @@
(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,41 @@
var getLoggedUserCountryLocs = Class.create();
getLoggedUserCountryLocs.prototype = {
initialize: function() {
},
getCountry: function() {

gs.addInfoMessage(gs.getUserID());
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id', gs.getUserID());
gr.query();
if (gr.next()) {
var loc = gr.location;
var country = gr.location.country;
}


var grUsers = new GlideRecord('cmn_location');

grUsers.addQuery('country', country);
grUsers.query();
var locs = "";
while (grUsers.next()) {

locs += grUsers.sys_id + ",";
}
gs.addInfoMessage(locs);
var users = new GlideRecord('sys_user');
users.addQuery('location', 'IN', locs);
users.query();

var l = "";
while (users.next()) {

l += users.sys_id + ",";

}
return 'sys_idIN' + l;
},

type: 'getLoggedUserCountryLocs'
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# getLoggedUserCountryLocs Script Include

## Overview

The **getLoggedUserCountryLocs** Script Include is a custom ServiceNow utility that retrieves all users who belong to the same **country** as the **currently logged-in user**.

It performs this by:
1. Fetching the logged-in user's country (based on their location record).
2. Identifying all location records that belong to the same country.
3. Gathering all users assigned to those locations.
4. Returning a GlideRecord-encoded query string (`sys_idIN...`) that can be used to filter or query other records.
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