Skip to content

Commit f057007

Browse files
authored
Merge branch 'ServiceNowDevProgram:main' into main
2 parents 3cee3e2 + 55d8b4b commit f057007

File tree

10 files changed

+694
-0
lines changed

10 files changed

+694
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Count Open Incidents per Priority Using GlideAggregate
2+
3+
## Overview
4+
This script dynamically calculates the **number of open incidents** for each priority level using **server-side scripting** in ServiceNow.
5+
Priority levels typically include:
6+
+ 1 – Critical
7+
+ 2 – High
8+
+ 3 – Moderate
9+
+ 4 – Low
10+
11+
The solution leverages **GlideAggregate** to efficiently count records grouped by priority. This approach is useful for:
12+
+ Dashboards
13+
+ Automated scripts
14+
+ Business rules
15+
+ SLA monitoring and reporting
16+
17+
---
18+
19+
## Table and Fields
20+
+ **Table:** `incident`
21+
+ **Fields:** `priority`, `state`
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
(function() {
2+
// Create GlideAggregate object on 'incident' table
3+
var ga = new GlideAggregate('incident');
4+
5+
// Filter only open incidents (state != Closed (7))
6+
ga.addQuery('state', '!=', 7);
7+
8+
// Group results by priority
9+
ga.groupBy('priority');
10+
11+
// Count number of incidents per priority
12+
ga.addAggregate('COUNT');
13+
14+
ga.query();
15+
16+
gs.info('Open Incidents by Priority:');
17+
18+
while (ga.next()) {
19+
var priority = ga.priority.getDisplayValue(); // e.g., Critical, High
20+
var count = ga.getAggregate('COUNT');
21+
gs.info(priority + ': ' + count);
22+
}
23+
})();
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
**Description:**
2+
This Script Include converts a Base64-encoded Active Directory (AD) Object GUID into its corresponding hexadecimal format.
3+
When importing AD objects from an on-premises directory using LDAP, the object GUIDs are typically stored in Base64 format.
4+
However, in OOB integrations such as the AD V2 Spoke, the GUID must be provided in hexadecimal format.
5+
This Script Include bridges that gap by decoding the Base64 string and converting it into the required hex representation.
6+
7+
**Usage:**
8+
Can be used in the LDAP Transofrm scripts to convert the base64 code to HEX code
9+
10+
**Sample:**
11+
12+
var base64Code ='ayn8QMpHEGezHQDdAQZi2g==';
13+
gs.print(new global.LDAP_AD_Utils().base64ToHex(base64Code));
14+
15+
**Output:**
16+
40fc296b-47ca-6710-b31d-00dd010662da
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
var LDAP_AD_Utils = Class.create();
2+
LDAP_AD_Utils.prototype = {
3+
initialize: function() {},
4+
5+
base64ToHex: function(str) {
6+
7+
var decoded = GlideStringUtil.base64DecodeAsBytes(str);
8+
9+
var n = decoded.length;
10+
11+
if (n < 16) {
12+
13+
return '';
14+
15+
}
16+
17+
var retVal = '';
18+
19+
retVal = retVal + this.prefixZeros(decoded[3] & 0xFF).toUpperCase();
20+
21+
retVal = retVal + this.prefixZeros(decoded[2] & 0xFF).toUpperCase();
22+
23+
retVal = retVal + this.prefixZeros(decoded[1] & 0xFF).toUpperCase();
24+
25+
retVal = retVal + this.prefixZeros(decoded[0] & 0xFF).toUpperCase();
26+
27+
retVal = retVal + '-';
28+
29+
retVal = retVal + this.prefixZeros(decoded[5] & 0xFF).toUpperCase();
30+
31+
retVal = retVal + this.prefixZeros(decoded[4] & 0xFF).toUpperCase();
32+
33+
retVal = retVal + '-';
34+
35+
retVal = retVal + this.prefixZeros(decoded[7] & 0xFF).toUpperCase();
36+
37+
retVal = retVal + this.prefixZeros(decoded[6] & 0xFF).toUpperCase();
38+
39+
retVal = retVal + '-';
40+
41+
retVal = retVal + this.prefixZeros(decoded[8] & 0xFF).toUpperCase();
42+
43+
retVal = retVal + this.prefixZeros(decoded[9] & 0xFF).toUpperCase();
44+
45+
retVal = retVal + '-';
46+
47+
retVal = retVal + this.prefixZeros(decoded[10] & 0xFF).toUpperCase();
48+
49+
retVal = retVal + this.prefixZeros(decoded[11] & 0xFF).toUpperCase();
50+
51+
retVal = retVal + this.prefixZeros(decoded[12] & 0xFF).toUpperCase();
52+
53+
retVal = retVal + this.prefixZeros(decoded[13] & 0xFF).toUpperCase();
54+
55+
retVal = retVal + this.prefixZeros(decoded[14] & 0xFF).toUpperCase();
56+
57+
retVal = retVal + this.prefixZeros(decoded[15] & 0xFF).toUpperCase();
58+
59+
return retVal.toLowerCase();
60+
61+
},
62+
63+
64+
prefixZeros: function(value) {
65+
66+
if (value <= 0xF) {
67+
68+
return '0' + value.toString(16);
69+
70+
} else {
71+
72+
return value.toString(16);
73+
74+
}
75+
76+
},
77+
78+
type: 'LDAP_AD_Utils'
79+
};
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
Script include is created as translationUtil for dynamic language translation. for example english to French
2+
3+
This script include for language translation will invoke flow designer action and sublfow to complete the real time language transaltion for instance suppose group table is updated with new group record having english as description text that can't be translated using OOTB translation tables in such scenario this UTIL will be a saviour
4+
5+
The properties referred in this translation util is DUMMY name that needs to be replaced with actual property name
6+
7+
You need to Identify the AI translator for your language and update accordingly.
8+
9+
More details....
10+
11+
This PR created for script include that contain TranslationUtil script and readme file that descrive 'How it server the purpose for Dynamic field translation using specific translator'
12+
13+
It will Fetches and calculates runtime limits for translation requests from system properties. Further it will dynamically retrieves the translation API key using getSubscriptionKey().
14+
15+
The scope of this utility ranges from multilingual support based on the user's preferred language to dynamic field translation through integration with Flows and Actions.
16+
17+
The scope of this PR & SI to provide a translationUtil, the custom flow action and subflow is not within the scope of this Util, if anyone wants to use it they need to create there own subflow that detect and translate the language by using this SI.
18+
19+
Details of Utils
20+
21+
TranslationUtils is a custom Script Include, created to manage dynamic text translation and language detection without depending on ServiceNow’s Out-of-the-box (OOTB) Translation plugin (like Dynamic Translation or Localization framework).
22+
How it Works?
23+
24+
It will look for Custom REST connections (via http_connection and api_key_credentials)
25+
Flow actions / subflows for actual translation and detection (global.detect_language, global.hhfksjhd__translate_text)
26+
Custom batching, size limits, and buffer logic to optimize translation requests and avoid API overflows.
27+
This SI will do the translation & detection of texts & give the translated data as JSON output
28+
HOPE THIS HELPS TO CLARIFY.

0 commit comments

Comments
 (0)