Skip to content

Commit bb43c5b

Browse files
authored
Merge branch 'main' into sixth-pull-request
2 parents edaf93b + 7078253 commit bb43c5b

File tree

8 files changed

+109
-1
lines changed

8 files changed

+109
-1
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Show Open Incident of caller
2+
3+
Script Type: UI Macro
4+
5+
Goal: In Form view caller can see what are the open incident of that particular caller.
6+
7+
Walk through of code: So for this use case a new macro will be added to the caller field, when it is triggered it will open a new popup window where it will show the list of particular caller which are all open incident.So for this a new UImacro have been used in that a new list icon have been rendered from the db_image table and inside that a showopentckts() function this will get the current caller and then add the query to filter out the list of open incident and then open a popup to show the list of that particular caller which are all open(other than Closed and Cancelled).
8+
9+
Note: To inherite the UI Macro in that particular field (Caller) we need to add the attribute in the Dictionary Entry = ref_contributions=caller_inc_lists [ref_contributions="name of the macro"]
10+
11+
UI Macro
12+
<img width="853" height="292" alt="UIMacro" src="https://github.com/user-attachments/assets/f5b353a2-ffb6-4e44-a740-9905b33cb484" />
13+
14+
Dictonary Entry in Attribute section
15+
<img width="848" height="386" alt="UIMacroDictionary" src="https://github.com/user-attachments/assets/b21d2077-3df5-4408-9bb3-c0672fd1398b" />
16+
17+
UI Macro in Incident Form near the Caller Field
18+
<img width="860" height="310" alt="From UIMacro" src="https://github.com/user-attachments/assets/c3867abf-f9cd-4947-a7e9-41c83189681d" />
19+
20+
Result:
21+
<img width="865" height="409" alt="UIMacro Result" src="https://github.com/user-attachments/assets/5412b29b-e96b-4455-a3e0-5552c9680600" />
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
3+
4+
<img src='sn_tile_icon/now-checklist.svg' stype='width=5%,height:5%' onclick="showopentckts()" title="Show Open Incident of me"></img>
5+
6+
<script language="javascript">
7+
function showopentckts(){
8+
var name=g_form.getValue("caller_id");
9+
var tableName='incident';
10+
var url=tableName+'_list.do?sysparm_query=caller_id='+name+'^stateNOT IN7,8';
11+
window.open(url,'OpenIncident',"popup");
12+
}
13+
14+
</script>
15+
16+
</j:jelly>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# ServiceNow Background Script – Identify Inactive Users with Open Incidents
2+
3+
This background script helps admin to identify **inactive users** who still have **open incidents** assigned to them.
4+
It’s particularly useful during **user cleanup, offboarding audits, or reassignment activities** to ensure no tickets remain unaddressed.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
var user = new GlideRecord('sys_user');
2+
user.addQuery('active', false);
3+
user.query();
4+
while (user.next()) {
5+
var inc = new GlideRecord('incident');
6+
inc.addQuery('assigned_to', user.sys_id);
7+
inc.addQuery('state', '!=', 7); // not Closed
8+
inc.query();
9+
while (inc.next()) {
10+
gs.info('Inactive user with open ticket: ' + user.name + ' → ' + inc.number);
11+
}
12+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
(function executeRule(current, previous /*null when async*/) {
2+
3+
// Run only when the Manager field changes
4+
if (current.manager.changes()) {
5+
6+
var groupID = current.sys_id.toString();
7+
8+
// Remove old manager from group membership
9+
if (!gs.nil(previous.manager)) {
10+
var oldMember = new GlideRecord('sys_user_grmember');
11+
oldMember.addQuery('group', groupID);
12+
oldMember.addQuery('user', previous.manager);
13+
oldMember.query();
14+
while (oldMember.next()) {
15+
oldMember.deleteRecord();
16+
}
17+
}
18+
19+
// Add new manager to group membership
20+
if (!gs.nil(current.manager)) {
21+
var newMember = new GlideRecord('sys_user_grmember');
22+
newMember.initialize();
23+
newMember.group = groupID;
24+
newMember.user = current.manager;
25+
newMember.insert();
26+
}
27+
}
28+
29+
})(current, previous);
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
When the Manager field changes on the Group table (sys_user_group), the system should automatically:
2+
3+
Remove the previous manager from the group’s membership.
4+
5+
Add the new manager as a member of the same group.

Specialized Areas/Fix scripts/Copy favourite to other users/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
**Enhancement**
2+
1. This code will create the sp favorites of the selected users along with the sys_ui_bookmarks.
3+
2. The entry will be made in "sp_favorite" through new **createPortalFav** function.
4+
15
You can use this script to take an existing favaourite from the sys_ui_bookmark table and create a copy of it for any number of users.
26
Can be useful when onboarding new staff, doing testing, etc.
37

Specialized Areas/Fix scripts/Copy favourite to other users/favCopy.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
var srcFav = ""; // Add the sys_id of the favourite to copy, from sys_ui_bookmark table
2+
var portalFav = ""; // Add the sys_id of the favourite to copy, from sp_favorite table.
23
var userCriteria = ""; // Add an encoded query of users from sys_user table
3-
44
var fav = new GlideRecord("sys_ui_bookmark");
55
fav.get(srcFav);
66

7+
var portalFavRec = new GlideRecord("sp_favorite");
8+
portalFavRec.get(portalFav); // glide record of favorite record.
9+
710
var users = new GlideRecord("sys_user");
811
users.addEncodedQuery(userCriteria);
912
users.query();
@@ -18,4 +21,18 @@ while(users.next()) {
1821
newFav.setValue("url",fav.url);
1922
newFav.setValue("user",users.sys_id);
2023
newFav.insert();
24+
25+
createPortalFav(users); // function to create portal favorites
26+
}
27+
function createPortalFav(userRec){
28+
var newPortalFav = new GlideRecord("sp_favorite");
29+
newPortalFav.initialize();
30+
newPortalFav.setValue('user',userRec.user);
31+
newPortalFav.setValue('reference_table',portalFavRec.reference_table);
32+
newPortalFav.setValue('reference_document',portalFavRec.reference_document);
33+
newPortalFav.setWorkflow(false); // OOB Sscript include take the logged-in user to check the duplicate records so workflow false restricts the SI to run.
34+
newPortalFav.insert();
2135
}
36+
37+
38+

0 commit comments

Comments
 (0)