Skip to content

Commit a890824

Browse files
authored
Merge branch 'ServiceNowDevProgram:main' into improve-ci-classes-readme
2 parents 37bec6a + 7a4e347 commit a890824

File tree

6 files changed

+106
-0
lines changed

6 files changed

+106
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
**Set and Lock Variable by Group**
2+
3+
This solution provides a secure and dynamic way to control data entry on a Service Catalog form based on the user's group membership. It is typically used to pre-fill and lock certain justification or approval bypass fields for authorized users (like managers or executive staff), improving their efficiency while maintaining an accurate audit trail.
4+
5+
This functionality requires a combined Client-side (Catalog Client Script) and Server-side (Script Include) approach to ensure the group check is done securely.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// onload Catalog Client Script with Catalog Name
2+
function onLoad() {
3+
var variableName = 'bypass_approval_reason';
4+
var targetGroupName = 'ServiceNow Support'; // The group authorized to skip this step
5+
var ga = new GlideAjax('UserUtils');
6+
ga.addParam('sysparm_name', 'isMemberOf');
7+
ga.addParam('sysparm_group_name', targetGroupName);
8+
ga.getXMLAnswer(checkAndLockVariable);
9+
function checkAndLockVariable(response) {
10+
var isMember = response;
11+
if (isMember == 'true') {
12+
var message = 'Value set and locked due to your ' + targetGroupName + ' membership.';
13+
var setValue = 'Bypassed by authorized ' + targetGroupName + ' member.';
14+
g_form.setValue(variableName, setValue);
15+
g_form.setReadOnly(variableName, true);
16+
g_form.showFieldMsg(variableName, message, 'info');
17+
} else {
18+
g_form.setReadOnly(variableName, false);
19+
}
20+
}
21+
}
22+
23+
//Script Include
24+
var UserUtils = Class.create();
25+
UserUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
26+
isMemberOf: function() {
27+
var groupName = this.getParameter('sysparm_group_name');
28+
var isMember = gs.getUser().isMemberOf(groupName);
29+
return isMember.toString();
30+
},
31+
32+
type: 'UserUtils'
33+
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
**Dynamic Reference Qualifier with Filtering**
2+
This Client Script provides a solution for dynamically updating the available options in a Reference Field based on the value selected in another field on the same form.
3+
4+
This technique is essential for ensuring data quality and improving the user experience (UX).
5+
6+
A typical use case is filtering the Assignment Group field to show only groups relevant to the selected Service, Category, or Location.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
2+
if (isLoading || newValue === '') {
3+
return;
4+
}
5+
var controlledField = 'assignment_group';
6+
var controllingField = 'u_service';
7+
var serviceSysId = g_form.getValue(controllingField);
8+
var encodedQuery = 'typeLIKEITIL^u_related_service=' + serviceSysId;
9+
g_form.setQuery(controlledField, encodedQuery);
10+
var currentGroupSysId = g_form.getValue(controlledField);
11+
if (currentGroupSysId && oldValue !== '' && currentGroupSysId !== '') {
12+
g_form.setValue(controlledField, '');
13+
}
14+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
## Overview
2+
This ServiceNow Business Rule automatically creates a Knowledge Article when an Incident is resolved and includes detailed resolution notes.
3+
It helps promote knowledge sharing, reduce repeated issues, and improve ITSM efficiency.
4+
5+
6+
## Features
7+
- Automatically creates a Knowledge Article in the **Draft** state.
8+
- Extracts content from the Incident's **Resolution Notes**.
9+
- Prevents duplicate Knowledge Articles by checking for similar issue titles.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
(function executeRule(current, previous) {
2+
3+
// Only run when the incident moves to Resolved
4+
if (current.state == previous.state || current.state != 6) {
5+
return;
6+
}
7+
8+
// Make sure we have resolution notes to use for the KB article
9+
if (!current.close_notes) {
10+
gs.info('Skipping KB creation: No resolution notes found for ' + current.number);
11+
return;
12+
}
13+
14+
// Get a clean version of the short description for comparison
15+
var issueTitle = current.short_description ? current.short_description.toLowerCase().trim() : '';
16+
17+
// Check if a similar KB article already exists
18+
var kbCheck = new GlideRecord('kb_knowledge');
19+
kbCheck.addQuery('short_description', 'CONTAINS', issueTitle);
20+
kbCheck.query();
21+
22+
if (kbCheck.next()) {
23+
gs.info('KB already exists for issue: ' + current.number + '. Skipping new KB creation.');
24+
return;
25+
}
26+
27+
// Create a new Knowledge Article
28+
var kb = new GlideRecord('kb_knowledge');
29+
kb.initialize();
30+
kb.short_description = current.short_description;
31+
kb.text = current.close_notes;
32+
kb.workflow_state = 'draft';
33+
kb.kb_category = ''; // You can set a default category if needed
34+
kb.u_source_incident = current.number; // Optional: track which incident created it
35+
kb.insert();
36+
37+
gs.info('New KB article created from Incident: ' + current.number);
38+
39+
})(current, previous);

0 commit comments

Comments
 (0)