Skip to content

Commit 4d95501

Browse files
authored
Utilizing spModal functionalities for SweetAlerts (#1740)
* spModalSweetAlerts.js spModal alerts are modern sweet alert to show the choices to be selected in an interactive way. Here, we are providing HR's to select the type of rewards in the modal page and populate a field with the selected value and show a message of the selected reward. * readme.md spModal alerts are modern sweet alert to show the choices to be selected in an interactive way. Here, we are providing HR's to select the type of rewards in the modal page and populate a field with the selected value and show a message of the selected reward. * readme.md spModal alerts are modern sweet alert to show the choices to be selected in an interactive way. Here, we are providing HR's to select the type of rewards in the modal page and populate a field with the selected value and show a message of the selected reward.
1 parent a2cb846 commit 4d95501

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
In ServiceNow, Open catalog client Scripts [catalog_script_client] and paste the code snippet of [spModalSweetAlerts.js] file.
2+
3+
Setup:
4+
1. A catalog item having variable name Rewards[rewards] of type 'Select Box'(include none as true) and 2 choices(Yes and No)
5+
2. A Single line type field named 'Reward Selected' [reward_selected] which will hold the value selected by user from the spModal popup.
6+
3. The onLoad catalog client script setup as below:
7+
4. Type: onChange
8+
5. Variable: rewards (as per step 1)
9+
6. Script: [[spModalSweetAlerts.js]]
10+
11+
12+
13+
Screenshots:
14+
15+
16+
<img width="1338" height="268" alt="image" src="https://github.com/user-attachments/assets/f7f22b83-7e0e-47bb-bbed-2a8f38783a4d" />
17+
18+
19+
Rewards selected as 'Yes'
20+
21+
<img width="1353" height="327" alt="image" src="https://github.com/user-attachments/assets/1bb55339-36b4-4a9c-8b65-2b254b87cf5b" />
22+
23+
From the spModal popup select anyone of the reward, it should be populated in the Reward Selected field.
24+
Along with that a message shows the same of the selection.
25+
26+
<img width="1350" height="319" alt="image" src="https://github.com/user-attachments/assets/1b23c766-51f8-4b01-9073-f836f390deb2" />
27+
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
function onChange(control, oldValue, newValue) {
2+
if (newValue == 'Yes') {
3+
spModal.open({
4+
title: "Reward Type",
5+
message: "Please select the category of Reward",
6+
buttons: [{
7+
label: "Star Performer",
8+
value: "Star Performer"
9+
},
10+
{
11+
label: "Emerging Player",
12+
value: "Emerging Player"
13+
},
14+
{
15+
label: "High Five Award",
16+
value: "High Five Award"
17+
},
18+
{
19+
label: "Rising Star",
20+
value: "Rising Star"
21+
}
22+
]
23+
}).then(function(choice) {
24+
if (choice && choice.value) {
25+
g_form.addInfoMessage('Selected Reward: '+ choice.label);
26+
g_form.setValue('reward_selected', choice.value);
27+
}
28+
});
29+
} else {
30+
g_form.clearValue('reward_selected');
31+
}
32+
}

0 commit comments

Comments
 (0)