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 Core ServiceNow APIs/GlideRecord/Order By Field/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Order By Scripts

This folder contains two JavaScript files that demonstrate sorting functionality.

## Files

- **orderByAscending.js** – Sorts data in ascending order.
- **orderByDescending.js** – Sorts data in descending order.

## Usage

Include either script in your file and call the respective function to sort your table as needed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
function ascOrder(tableName, field) {
var tableGr = new GlideRecord(tableName);
tableGr.addActiveQuery();
tableGr.orderBy(field);
tableGr.query();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
function ascOrder(tableName, field) {
var tableGr = new GlideRecord(tableName);
tableGr.addActiveQuery();
tableGr.orderByDesc(field);
tableGr.query();
}
9 changes: 9 additions & 0 deletions Duplicate Attachment Finder/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Duplicate Attachment Finder

This script identifies duplicate attachments in a ServiceNow instance based on file name and size, and lists them in descending order of creation date.

## Features

- Finds attachments with the same **file name** and **size**.
- Orders duplicates by **creation date (latest first)**.
- Shows the **attachment Sys ID**, **parent table**, and **record**.
43 changes: 43 additions & 0 deletions Duplicate Attachment Finder/duplicateAttachments.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
(function() {
var attachmentGr = new GlideRecord('sys_attachment');
attachmentGr.orderByDesc('sys_created_on');
attachmentGr.query();

var attachments = {};
var duplicateList = [];

while(attachmentGr.next()) {
var key = attachmentGr.file_name + '|' + attachmentGr.size_bytes;
if(!attachments[key]) {
attachments[key] = [];
}
attachmentGr[key].push({
sys_id: attachmentGr.sys_id.toString(),
table_name: attachmentGr.table_name.toString(),
table_sys_id: attachmentGr.table_sys_id.toString,
created_on: attachmentGr.sys_created_on.toString()
})
}

for (var i in attachments) {
if(attachments[i].length > 1) {
duplicateList.push({
file_key: i,
count: attachments[i].length,
records: attachments[i]
})
}
}

if (duplicateList.length === 0) {
gs.info('No duplicate attachments found.');
} else {
gs.info('Found ' + duplicateList.length + ' duplicate attachments:');
duplicateList.forEach(function(dup) {
gs.info('File: ' + dup.file_key + ' | Count: ' + dup.count);
dup.records.forEach(function(r) {
gs.info(' Sys_ID: ' + r.sys_id + ' | Table: ' + r.table_name + ' | Record: ' + r.table_sys_id + ' | Created On: ' + r.created_on);
});
});
}
}());
Loading