- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
7 hours ago
Hello,
I have an spModal with two buttons. I would like to display a message to the user when the "Agree" button is selected, and a different message when the "Disagree" button is selected. In addition, if the user closes the modal by clicking the "X" icon, no message should appear. How to make this work?
spModal.open({
"title" : "Terms&Conditions",
"message" : message,
"buttons" : [
{label: "Agree" , primary: true},
{label: "Disagree" , cancel: true}
],
"backdrop" : "static",
"keyboard": false
})
Thanks,
Smith.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
6 hours ago
this worked for me, enhance further
spModal.open({
title: 'Custom Action Required',
message: 'Please choose an action:',
buttons: [{
label: 'Agree',
value: 'agree',
primary: true // Makes this button visually prominent
}, {
label: 'Disagree',
value: 'disagree'
}]
}).then(function(result) {
// This function executes when a button is clicked
if (!result.primary) {
alert('You clicked disagree!');
} else {
alert('You clicked agree!');
}
});
Output:
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
7 hours ago
try this
spModal.open({
"title": "Terms & Conditions",
"message": message,
"buttons": [
{ label: "Agree", primary: true },
{ label: "Disagree", cancel: true }
],
"backdrop": "static",
"keyboard": false,
"callback": function(result) {
if (result === "Agree") {
// Show message for Agree
alert("You agreed to the terms.");
} else if (result === "Disagree") {
// Show message for Disagree
alert("You disagreed to the terms.");
}
// No message if modal is closed with "X" (result will be undefined or null)
}
});
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
7 hours ago
Hello @Ankur Bawiskar ,
unless I miss something, this didnt work. I also put some log statements, but I don't see anything in the console.
spModal.open({
"title": "Terms & Conditions",
"message": "message",
"buttons": [{
label: "Agree",
primary: true
},
{
label: "Disagree",
cancel: true
}
],
"backdrop": "static",
"keyboard": false,
"callback": function(result) {
if (result === "Agree") {
console.log("triggered");
// Show message for Agree
alert("You agreed to the terms.");
} else if (result === "Disagree") {
// Show message for Disagree
console.log("triggered 2");
alert("You disagreed to the terms.");
}
console.log("triggered 3");
// No message if modal is closed with "X" (result will be undefined or null)
}
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
6 hours ago
this worked for me, enhance further
spModal.open({
title: 'Custom Action Required',
message: 'Please choose an action:',
buttons: [{
label: 'Agree',
value: 'agree',
primary: true // Makes this button visually prominent
}, {
label: 'Disagree',
value: 'disagree'
}]
}).then(function(result) {
// This function executes when a button is clicked
if (!result.primary) {
alert('You clicked disagree!');
} else {
alert('You clicked agree!');
}
});
Output:
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
5 hours ago
thank you @Ankur Bawiskar , this indeed worked 🙂
