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
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);
15 changes: 15 additions & 0 deletions Server-Side Components/Business Rules/EmailAlert/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
**Overview**
This implementation demonstrates how to display the Caller’s email address in an alert whenever an Incident form is loaded in ServiceNow.
It uses a Business Rule to fetch the email and a Client Script to display it on the form.

Components:
Business Rule: Fetches the Caller’s email and stores it in a temporary variable (g_scratchpad) to be used on the client side.
Client Script (onLoad): Reads the email from g_scratchpad and displays it in an alert when the form is loaded.

Usage:
Apply the Business Rule to the Incident tabl and add the Client Script (onLoad) to the same table.
When an existing Incident record is opened, the Caller’s email will appear in a pop-up alert.

Result
Existing Incident records show an alert with the Caller’s email address.
New records do not trigger the alert.
26 changes: 26 additions & 0 deletions Server-Side Components/Business Rules/EmailAlert/emailAlert.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#BusinessRule
(function executeRule(current, previous /*null when async*/) {

// Add your code here
if(!current.isNewRecord()){
var gr=new GlideRecord('incident');
gr.addQuery('parent_incident',current.sys_id);
gr.query();
var c=gr.getRowCount();

g_scratchpad.num=c;
}

})(current, previous);

#ClientScript

function onLoad() {
//Type appropriate comment here, and begin script below
var res=g_form.isNewRecord();
if(!res){
var number=g_scratchpad.num;
alert("Child incident count of this record :"+number);
}

}
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