Skip to content

Commit f2ce7d2

Browse files
authored
Merge branch 'ServiceNowDevProgram:main' into main
2 parents f368a8d + 0da4fa8 commit f2ce7d2

File tree

25 files changed

+691
-20
lines changed

25 files changed

+691
-20
lines changed
79.2 KB
Loading
73.5 KB
Loading
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
## Display Info Message of Incident Count of Assigned-To User When Field Assigned-To Changes
2+
3+
Displays a message showing the count of **open incidents** assigned to a user whenever the **Assigned To** field changes on the Incident form.
4+
5+
- Helps assess the assignee’s **current workload** by fetching and displaying active incident counts (excluding *Resolved*, *Closed*, and *Canceled* states)
6+
- Shows an **info message** with the count of the assignee's assigned incidents
7+
- Uses an **onChange Client Script** on the **Assigned To** field and a **GlideAjax Script Include** called from the client script to fetch the count dynamically
8+
9+
---
10+
11+
### Info Message Example 1
12+
![Incident_Count_message_1](Incident_Count_message_1.png)
13+
14+
### Info Message Example 2
15+
![Incident_Count_message_2](Incident_Count_message_2.png)
16+
17+
---
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
2+
if (isLoading || newValue === '') return;
3+
4+
// Clear any previous messages
5+
g_form.clearMessages();
6+
7+
// Create GlideAjax object to call the Script Include
8+
var ga = new GlideAjax('IncidentAssignmentCheck');
9+
ga.addParam('sysparm_name', 'getIncidentCount');
10+
ga.addParam('sysparm_user', newValue);
11+
12+
13+
ga.getXMLAnswer(function(response) {
14+
var count = parseInt(response, 10);
15+
16+
17+
if (isNaN(count)) {
18+
g_form.addErrorMessage("Could not retrieve open incident count.");
19+
return;
20+
}
21+
22+
var userName = g_form.getDisplayValue('assigned_to');
23+
var msg = userName + " currently has " + count + " incidents assigned ";
24+
25+
if (count >= 5) {
26+
g_form.addInfoMessage(msg + " Please review workload before assigning more incidents");
27+
} else {
28+
g_form.addInfoMessage(msg);
29+
}
30+
});
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
var IncidentAssignmentCheck = Class.create();
2+
IncidentAssignmentCheck.prototype = Object.extendsObject(AbstractAjaxProcessor, {
3+
4+
getIncidentCount: function() {
5+
var user = this.getParameter('sysparm_user');
6+
var count = 0;
7+
8+
if (user) {
9+
var gr = new GlideAggregate('incident');
10+
gr.addQuery('assigned_to', user);
11+
gr.addQuery('state', 'NOT IN', '6,7,8');
12+
gr.addAggregate('COUNT');a
13+
gr.query();
14+
15+
if (gr.next()) {
16+
count = gr.getAggregate('COUNT');
17+
}
18+
}
19+
return count;
20+
},
21+
22+
type: 'IncidentAssignmentCheck'
23+
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Dynamic script to make fields read only
2+
3+
It runs when the field value changes.On change client script
4+
If the new value equals '7', it retrieves all editable fields using g_form.getEditableFields().
5+
Then it loops through each field and sets it to read-only using g_form.setReadOnly().
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
It runs when the field value changes.
3+
If the new value equals '7', it retrieves all editable fields using g_form.getEditableFields().
4+
Then it loops through each field and sets it to read-only using g_form.setReadOnly().
5+
6+
*/
7+
8+
9+
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
10+
if (isLoading || newValue === '') {
11+
return;
12+
}
13+
14+
15+
if (newValue == '7') { // update condition as required
16+
var fields = g_form.getEditableFields();
17+
for (var i = 0; i < fields.length; i++) {
18+
g_form.setReadOnly(fields[i].getName(), true);
19+
}
20+
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# CancelFlow UI Action
2+
3+
A ServiceNow utility that dynamically cancels flows associated with the current record, ensuring seamless process management.
4+
5+
## Challenge
6+
7+
Managing running flows in ServiceNow can be challenging, particularly when multiple flows are tied to a single record. This utility streamlines the process by offering a dynamic solution to identify and cancel running flows, minimizing manual intervention and ensuring seamless operations.
8+
9+
This tool is especially useful in scenarios where you need to halt the current execution and initiate a new flow or process. Additionally, it can be leveraged to forcefully terminate the automation lifecycle when necessary, providing greater control over flow management.
10+
11+
## Description
12+
13+
This UI Action is designed to identify and cancel all running flows associated with the current record in a ServiceNow instance. It provides a user-friendly interface for administrators and developers to manage flow cancellations efficiently. This utility is particularly useful in scenarios where flows need to be terminated to prevent conflicts or errors during record updates.
14+
15+
## Functionality
16+
17+
The CancelFlow UI Action provides the following capabilities:
18+
- Dynamically identifies running flows for the current record.
19+
- Cancels the identified flows programmatically.
20+
- Displays success or error messages to the user for better visibility.
21+
- Ensures smooth handling of flow cancellations without manual intervention.
22+
23+
## Usage Instructions
24+
25+
### UI Action Script
26+
27+
Add the given script to your UI Action:
28+
29+
30+
### Example Usage
31+
32+
1. Open the record where you want to cancel the associated flows.
33+
2. Click on the **Cancel Flow** UI Action button.
34+
3. The system will identify and cancel all running flows for the current record.
35+
4. The same can be used in Business rules as well based on trigger conditions
36+
37+
38+
### Visibility for UI Action
39+
40+
In certain scenarios, it may be necessary to restrict the visibility of this operation to specific user groups. For example, only HR administrators or members of a designated group (e.g., "X Group") should have access to this functionality. These requirements can be addressed by configuring the **Condition** field in the UI Action. You can tailor the conditions to align with your specific use case, ensuring that only authorized users can execute this operation. One edge case about not having an active flow execution can also be handled in the condition which will restrict the visibility if no active flow execution is present.
41+
42+
43+
## Dependencies
44+
45+
- `sn_fd.FlowAPI`
46+
47+
## Category
48+
49+
Client-Side Components / UI Actions
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
function cancelRunningFlows() {
2+
3+
try {
4+
var grFlowExecution = new GlideRecord("sys_flow_context");
5+
grFlowExecution.addQuery("source_record", current.sys_id);
6+
grFlowExecution.query();
7+
8+
while (grFlowExecution.next()) {
9+
sn_fd.FlowAPI.cancel(grFlowExecution.getUniqueValue(), "Canceling Flows");
10+
}
11+
} catch (error) {
12+
gs.error("Error cancelling flows: " + error.message);
13+
}
14+
}
15+
16+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Loaders UI Page
2+
3+
This UI Page showcases a collection of loaders and spinners designed to visually represent ongoing processes in web applications. These components enhance user experience by providing clear feedback during data loading or processing.
4+
5+
## Features
6+
- A diverse set of loader and spinner designs.
7+
- Fully responsive and easily customizable.
8+
- Lightweight and seamlessly integrable into glideModal or other UI components.
9+
10+
11+
## Usage
12+
1. Select the desired loader's HTML and CSS code from the examples.
13+
2. Go to the Application Navigator and search for UI Pages under **System UI > UI Pages**.
14+
3. Click on New and create new record by adding given HTML in the HTML section.
15+
4. Adjust the styles as needed to align with your design requirements.
16+
17+

0 commit comments

Comments
 (0)