Skip to content

Commit 3d5e590

Browse files
authored
Merge branch 'ServiceNowDevProgram:main' into main
2 parents dd25d58 + 8e89998 commit 3d5e590

File tree

64 files changed

+1933
-167
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+1933
-167
lines changed

.github/workflows/pr-auto-unassign-stale.yml

Lines changed: 0 additions & 154 deletions
This file was deleted.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Unassign stale PR assignees
2+
on:
3+
schedule:
4+
- cron: "*/15 * * * *"
5+
workflow_dispatch:
6+
inputs:
7+
enabled: { type: boolean, default: true }
8+
max_age_minutes: { type: number, default: 60 }
9+
dry_run: { type: boolean, default: false }
10+
11+
permissions:
12+
pull-requests: write
13+
issues: write
14+
contents: read
15+
16+
jobs:
17+
call:
18+
uses: ServiceNowDevProgram/Hacktoberfest/.github/workflows/unassign-stale.yml@b8c3f56f94d96f263420e2c051d91b791c9494d8
19+
with:
20+
enabled: ${{ inputs.enabled }}
21+
max_age_minutes: ${{ inputs.max_age_minutes }}
22+
dry_run: ${{ inputs.dry_run }}
23+
secrets: inherit
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
The script enhances a form field (specifically the description field) by:
2+
-Adding a live word counter below the field.
3+
-Visually warning the user if the word count exceeds 150 words.
4+
5+
This client-side script, intended for use in a ServiceNow form (e.g., catalog item or incident form), dynamically appends a custom `<div>` element below the `description` field to display a real-time word count. It leverages the `g_form.getControl()` API to access the field's DOM element and attaches an `input` event listener to monitor user input. The script calculates the word count by splitting the input text using a regular expression (`\s+`) and updates the counter accordingly. It applies conditional styling to the counter (`green` if ≤150 words, `red` if >150), providing immediate visual feedback to the user to enforce input constraints.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
2+
if (isLoading || newValue === oldValue) {
3+
return;
4+
}
5+
6+
var wordCount = newValue.trim().split(/\s+/).length;
7+
var message = 'Word Count: ' + (newValue ? wordCount : 0);
8+
var messageType = (wordCount > 150) ? 'error' : 'info';
9+
10+
g_form.showFieldMsg('description', message, messageType);
11+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Smart Field Suggestions Based on Keywords
2+
3+
## Category
4+
Client-Side Components / Client Scripts
5+
6+
## Description
7+
This is an onChange Client Script designed for the Incident table that dynamically suggests and populates the Category, Subcategory, and Priority fields based on keywords detected in the Short Description field. By matching keywords, it prompts users to confirm applying suggestions aligned with backend choice values for seamless integration.
8+
9+
## Use Case
10+
During incident creation or update, manually categorizing tickets correctly is critical for IT operations efficiency. This snippet automates early triage by analyzing user-entered short descriptions, providing actionable suggestions to improve categorization accuracy, accelerate routing, and enhance resolution speed.
11+
12+
## How to Use
13+
- Add this script as an "onChange" client script on the Incident table's `short_description` field.
14+
- Ensure the Category, Subcategory, and Priority fields have choice lists aligned with backend values specified in the snippet.
15+
- Modify the keyword list to align with your organizational terminologies if needed.
16+
- The user will be prompted with suggestions and may confirm or dismiss them, allowing balanced automation and human control.
17+
18+
## Why This Use Case is Unique and Valuable
19+
20+
- Dynamically assists in categorizing incidents early, improving routing and resolution time.
21+
- Uses only platform APIs (`g_form`) without custom backend code or external integrations, making it lightweight and maintainable.
22+
- Uses real backend choice values ensuring seamless compatibility with existing configurations, reducing errors.
23+
- Provides prompt suggestions with user confirmation, balancing automation and user control.
24+
- Easily adaptable for other fields, keywords, or use cases beyond Incident management.
25+
- Designed without fragile DOM manipulations, following ServiceNow best practices, tailored for real environments.
26+
27+
## Compatibility
28+
This client script is compatible with all standard ServiceNow instances without requiring ES2021 features.
29+
30+
## Files
31+
- `Smart Field Suggestions Based on Keyword.js` — the client script implementing the logic.
32+
33+
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
2+
if (isLoading || !newValue || newValue.length < 10) {
3+
return;
4+
}
5+
6+
var keywords = [
7+
{
8+
pattern: /password|login|access/i,
9+
category: 'inquiry | Help ',
10+
subcategory: 'antivirus',
11+
priority: '3',
12+
suggestion: 'This appears to be a Inquiry issue.'
13+
},
14+
{
15+
pattern: /slow|performance|hanging/i,
16+
category: 'software',
17+
subcategory: 'email',
18+
priority: '2',
19+
suggestion: 'This appears to be a Software issue.'
20+
},
21+
{
22+
pattern: /printer|print|printing/i,
23+
category: 'hardware',
24+
subcategory: 'monitor',
25+
priority: '3',
26+
suggestion: 'This appears to be a Hardware issue.'
27+
},
28+
{
29+
pattern: /database|data/i,
30+
category: 'database',
31+
subcategory: 'db2',
32+
priority: '3',
33+
suggestion: 'This appears to be an Database issue.'
34+
},
35+
{
36+
pattern: /network|internet|wifi|connection/i,
37+
category: 'network',
38+
subcategory: 'vpn',
39+
priority: '2',
40+
suggestion: 'This appears to be a network issue.'
41+
}
42+
43+
];
44+
45+
var lowerDesc = newValue.toLowerCase();
46+
var matched = null;
47+
48+
for (var i = 0; i < keywords.length; i++) {
49+
if (keywords[i].pattern.test(lowerDesc)) {
50+
matched = keywords[i];
51+
break;
52+
}
53+
}
54+
55+
g_form.hideFieldMsg('short_description', true);
56+
g_form.clearMessages();
57+
58+
if (matched) {
59+
g_form.showFieldMsg('short_description', matched.suggestion, 'info', false);
60+
61+
if (confirm(matched.suggestion + "\n\nApply these suggestions?")) {
62+
g_form.setValue('category', matched.category);
63+
g_form.setValue('subcategory', matched.subcategory); // Make sure you use backend value for subcategory!
64+
g_form.setValue('priority', matched.priority);
65+
g_form.addInfoMessage('Suggestions applied automatically!');
66+
} else {
67+
g_form.addInfoMessage('Suggestions dismissed.');
68+
g_form.hideFieldMsg('short_description', true);
69+
}
70+
} else {
71+
g_form.addInfoMessage('No keywords matched in description.');
72+
}
73+
}
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
onSubmit Function: This client script validates the email format when the form is submitted.
2-
Regular Expression: It uses a regex pattern to check if the entered email matches a standard email format.
2+
Regular Expression: It uses a comprehensive email regex pattern to check if the entered email matches a standard email format.
3+
4+
This pattern can handles:
5+
- Quoted local parts (`"john doe"@example.com`)
6+
- Dots within the local segment (`first.m.last@subdomain.org`)
7+
- IP-based domains (`user@[192.168.1.1]`)
8+
39
Error Message: If the email is invalid, an error message is displayed, and form submission is prevented.

Client-Side Components/Client Scripts/Validate Email Format/ValidateEmailFormat.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
function onSubmit() {
44
var emailField = g_form.getValue('email');
5-
var emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
5+
//Comprehensive email regex pattern
6+
var emailPattern = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
67

78
if (!emailPattern.test(emailField)) {
89
g_form.addErrorMessage('Please enter a valid email address.');
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Smart Field Validation and Dependent Field Derivation Using GlideElement.getError()
2+
3+
This project demonstrates how to use `GlideElement.setError()` and `GlideElement.getError()`
4+
to perform validation in one Business Rule and field derivation in another, without repeating logic.
5+
6+
## 📘 Overview
7+
8+
This snippet demonstrates how to share validation state and error messages between multiple Business Rules using `GlideElement.setError()` and `GlideElement.getError()` in ServiceNow.
9+
10+
By propagating validation context across Business Rules, developers can:
11+
12+
- Avoid repeated validation logic.
13+
- Trigger dependent field updates only when a field passes validation.
14+
- Maintain consistent and clean data flow between sequential rules.
15+
16+
This technique is especially useful when different validation or derivation rules are split by purpose or owned by different teams.
17+
18+
---
19+
20+
## 🧠 Concept
21+
22+
When one Business Rule sets an error on a field using `setError()`, the error message persists in memory for that record during the same transaction.
23+
A later Business Rule (executing at a higher order) can then retrieve that message using `getError()` and make data-driven decisions.
24+
25+
### Flow:
26+
1. BR #1 (`Validate Short Description`) checks text length.
27+
2. BR #2 (`Derive Dependent Fields`) runs only if no validation error exists.
28+
3. Category, Subcategory, and Impact are derived dynamically.
29+
30+
## 🚀 Benefits
31+
32+
- ✅ Reduces redundant validation checks
33+
- ✅ Improves rule execution efficiency
34+
- ✅ Keeps logic modular and maintainable
35+
- ✅ Provides better visibility and control in field validations

0 commit comments

Comments
 (0)