Skip to content

Commit 015106f

Browse files
authored
Glide Modal Ui pop Confirmation box (#1288)
* Create readme.md this readme file contains all the details of the purpose of the ui action and the execution steps * Update readme.md Added details of this ui action how it is being executed and it works * Create glide_modal_ui_pop_up.js this file contains ui action script
1 parent 5872bdc commit 015106f

File tree

2 files changed

+84
-0
lines changed

2 files changed

+84
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
function onClick(g_form) {
2+
// Check if the current user is the assigned user
3+
if (g_user.userID != g_form.getValue('assigned_to')) {
4+
// Alert if the user is not the assigned user
5+
g_modal.alert('Only the assigned user can perform this action.');
6+
return;
7+
}
8+
9+
// Confirmation message
10+
var msg = getMessage("Are you sure you want to take this action?");
11+
12+
// Confirmation modal before closing the task
13+
g_modal.confirm(getMessage("Confirmation"), msg, function (confirmed) {
14+
if (confirmed) {
15+
// If confirmed, close the task
16+
g_form.setValue('state', 'closed_complete');
17+
g_form.save();
18+
}
19+
});
20+
21+
return false;
22+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
Overview
2+
Modal alerts and confirmations in ServiceNow are interactive user interface elements that allow users to receive important messages or confirm actions before proceeding. These modals enhance the user experience by providing clear feedback during key interactions, ensuring that users are well-informed before performing potentially critical actions, such as closing a record or saving changes.
3+
4+
Two key modal functions used in ServiceNow are:
5+
6+
g_modal.alert(): Displays an informational message to the user.
7+
g_modal.confirm(): Requests user confirmation before proceeding with an action.
8+
Key Features:
9+
Clarity: Provides clear messaging for users, helping them understand the consequences of their actions.
10+
User Control: Allows users to confirm or cancel actions, reducing mistakes.
11+
Customizable: Modal messages can be tailored to different scenarios, ensuring contextual and relevant feedback.
12+
Testing
13+
To test the modal alerts and confirmations, follow these steps:
14+
15+
1. User Scenario Setup:
16+
Create a form with an assigned_to field and ensure that different users can access the form.
17+
Set up a button or UI action that triggers the onClick() function.
18+
2. Test Case 1: Unauthorized User
19+
Log in as a user who is not assigned to the task.
20+
Click the button to trigger the action.
21+
Expected Result: The user should receive an alert stating "Only the assigned user can perform this action." The process should stop here.
22+
3. Test Case 2: Authorized User
23+
Log in as the user who is assigned to the task.
24+
Click the button to trigger the action.
25+
Expected Result: A confirmation dialog should appear asking, "Are you sure you want to take this action?"
26+
If the user clicks "Cancel," no action should be taken.
27+
If the user clicks "OK," the task's state should be set to "Closed Complete," and the form should be saved.
28+
4. Edge Cases:
29+
Test what happens if the task has no assigned user.
30+
Test if the modals display correctly on different devices (desktop, mobile, etc.).
31+
5. Performance:
32+
Ensure that the modals load quickly and do not interfere with other form functions.
33+
How It Works
34+
The modal alert and confirmation functions are built on the ServiceNow UI framework and use JavaScript to control the interactions.
35+
36+
Alert Modal (g_modal.alert()):
37+
This function is used to inform the user without requiring any further input.
38+
It takes three arguments: the title of the alert, the message to display, and an optional callback function that can execute code after the alert is closed.
39+
Once triggered, the user sees a message box with only an "OK" button.
40+
Confirmation Modal (g_modal.confirm()):
41+
This function prompts the user to confirm their action with two options: "OK" or "Cancel."
42+
It takes three arguments: the title of the confirmation modal, the message, and a callback function.
43+
The callback function receives a confirmed argument that is true if the user clicks "OK" and false if they click "Cancel."
44+
This is useful in scenarios where user confirmation is critical (e.g., deleting a record, submitting a form).
45+
Process Flow:
46+
The system checks if the logged-in user has permission to perform the action (e.g., checking if the user matches the assigned_to field).
47+
If the user is not authorized, an alert modal is displayed, and the process stops.
48+
If the user is authorized, a confirmation modal is displayed to ask for final approval.
49+
If confirmed, the system proceeds with the action (e.g., changing the record state and saving the form).
50+
Benefits
51+
1. Improved User Experience:
52+
Modal alerts and confirmations provide immediate feedback to users. By using clear language in modals, users understand exactly what actions they can or cannot perform.
53+
Confirmation dialogs prevent accidental actions, which is especially useful in critical workflows (e.g., closing or deleting records).
54+
2. Reduced Errors:
55+
Alerts help users understand why an action is restricted, while confirmations ensure that actions are intentional.
56+
This reduces the risk of accidental data changes or loss.
57+
3. Increased Control:
58+
By requiring confirmation before a critical action is taken, users feel more in control of their tasks. They are prompted to reconsider their choices, which minimizes hasty decisions.
59+
4. Customization:
60+
Modal alerts and confirmations can be easily customized for various forms and records, allowing tailored feedback depending on the context of the action.
61+
5. Asynchronous Operations:
62+
Modals are asynchronous, meaning they don't block the user interface while waiting for input. This ensures that other parts of the application continue functioning smoothly.

0 commit comments

Comments
 (0)