why confirm() is not working in ui action button
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2025 01:24 AM
16 REPLIES 16
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2025 02:11 AM - edited 02-24-2025 02:11 AM
To save on server side, you have to write server side code in UI action. For that you need to add below "if block" of code in your UI action.
function reset_password() {
var con = confirm('Are you sure');
if(con){
gsftSubmit(null, g_form.getFormElement(), 'reset_password');
}
}
if(typeof window == 'undefined') {
// Add Server side logic Eg: I have changed the short_description and then update
current.short_description = 'Test';
current.update();
}
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2025 03:00 AM
Write client side UI action and call script include from it, below is the sample code:
UI action:
function confirmResetPassword() {
var answer = confirm("Are you sure you want to reset the password?");
if (answer) {
// Call a Script Include or trigger server-side logic
var ga = new GlideAjax('PasswordResetScriptInclude');
ga.addParam('sysparm_name', 'resetPassword');
ga.addParam('sysparm_sys_id', g_form.getUniqueValue());
ga.getXMLAnswer(function(response) {
alert(response); // Show success or error message
});
}
}
confirmResetPassword();
Script inlcude:
var PasswordResetScriptInclude = Class.create();
PasswordResetScriptInclude.prototype = {
initialize: function() {},
resetPassword: function() {
var sys_id = gs.getParameter('sysparm_sys_id');
if (!sys_id) return "Invalid record";
var inc = new GlideRecord('incident');
if (inc.get(sys_id)) {
return "Password reset request submitted successfully.";
}
return "Incident not found.";
},
type: 'PasswordResetScriptInclude'
};
Please mark correct/helpful if this helps you!