The CreatorCon Call for Content is officially open! Get started here.

g_modal is not working as expected in declarative list action

APV Babu
Tera Contributor

I am tryign to show a modal confirm message when deleting the records I am using g_modal it is not working 

 

APVBabu_0-1760001929088.png

 

 

Regards,

APV Babu

 

 

2 ACCEPTED SOLUTIONS

M Iftikhar
Giga Sage

Hi @APV Babu ,

you’re trying to show a confirmation modal before deleting a record, but g_modal isn’t working.

g_modal only works in UI Builder or Now Experience, not in classic UI.

 Classic UI (use gsftConfirm)

function onClick(g_form) {
    if (g_user.userID != g_form.getValue('created_by')) {
        alert('Only the assigned user can end this action.');
        return;
    }

    var msg = "Are you sure you want to take this action?";
    gsftConfirm(msg, function(confirmed) {
        if (confirmed) {
            g_form.setValue('state', 'closed_complete');
            g_form.save();
        }
    });
    return false;
}

UI Builder / Now Experience (use g_modal.confirm)

g_modal.confirm('Are you sure?', 'Confirmation', function(confirmed) {
    if (confirmed) {
        g_form.setValue('state', 'closed_complete');
        g_form.save();
    }
});

Summary:

  • Classic UI → gsftConfirm()

  • UI Builder → g_modal.confirm()


If my response helped, please mark it as the accepted solution so others can benefit as well.  
 

Thanks & Regards,
Muhammad Iftikhar

If my response helped, please mark it as the accepted solution so others can benefit as well.

View solution in original post

Ravi Gaurav
Giga Sage
Giga Sage

Hi @APV Babu 
Below will help you to understand!!

 

 

Confirm Modals in ServiceNow

UI Type Supported Method Example Notes
Classic UI (forms, lists) gsftConfirm() ```javascript  
function onClick(g_form) {      
if (g_user.userID != g_form.getValue('created_by')) {      

 

 
alert('Only the assigned user can end this action.'); return;

}

var msg = "Are you sure you want to take this action?";
gsftConfirm(msg, function(confirmed) {
if (confirmed) {
g_form.setValue('state', 'closed_complete');
g_form.save();
}
});
return false;
}

 

-----------------------
 

| **UI Builder / Now Experience** | `g_modal.confirm()` | ```javascript
g_modal.confirm('Are you sure?', 'Confirmation', function(confirmed) {
if (confirmed) {
g_form.setValue('state', 'closed_complete');
g_form.save();
}
});
``` | Works only in **UI Builder / Workspace** components that support the `g_modal` API. |

---

--------------------------------------------------------------------------------------------------------------------------


If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!

Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI

 YouTube: https://www.youtube.com/@learnservicenowwithravi
 LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/

View solution in original post

4 REPLIES 4

M Iftikhar
Giga Sage

Hi @APV Babu ,

you’re trying to show a confirmation modal before deleting a record, but g_modal isn’t working.

g_modal only works in UI Builder or Now Experience, not in classic UI.

 Classic UI (use gsftConfirm)

function onClick(g_form) {
    if (g_user.userID != g_form.getValue('created_by')) {
        alert('Only the assigned user can end this action.');
        return;
    }

    var msg = "Are you sure you want to take this action?";
    gsftConfirm(msg, function(confirmed) {
        if (confirmed) {
            g_form.setValue('state', 'closed_complete');
            g_form.save();
        }
    });
    return false;
}

UI Builder / Now Experience (use g_modal.confirm)

g_modal.confirm('Are you sure?', 'Confirmation', function(confirmed) {
    if (confirmed) {
        g_form.setValue('state', 'closed_complete');
        g_form.save();
    }
});

Summary:

  • Classic UI → gsftConfirm()

  • UI Builder → g_modal.confirm()


If my response helped, please mark it as the accepted solution so others can benefit as well.  
 

Thanks & Regards,
Muhammad Iftikhar

If my response helped, please mark it as the accepted solution so others can benefit as well.

Ankur Bawiskar
Tera Patron
Tera Patron

@APV Babu 

what's your actual business requirement here?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Ravi Gaurav
Giga Sage
Giga Sage

Hi @APV Babu 
Below will help you to understand!!

 

 

Confirm Modals in ServiceNow

UI Type Supported Method Example Notes
Classic UI (forms, lists) gsftConfirm() ```javascript  
function onClick(g_form) {      
if (g_user.userID != g_form.getValue('created_by')) {      

 

 
alert('Only the assigned user can end this action.'); return;

}

var msg = "Are you sure you want to take this action?";
gsftConfirm(msg, function(confirmed) {
if (confirmed) {
g_form.setValue('state', 'closed_complete');
g_form.save();
}
});
return false;
}

 

-----------------------
 

| **UI Builder / Now Experience** | `g_modal.confirm()` | ```javascript
g_modal.confirm('Are you sure?', 'Confirmation', function(confirmed) {
if (confirmed) {
g_form.setValue('state', 'closed_complete');
g_form.save();
}
});
``` | Works only in **UI Builder / Workspace** components that support the `g_modal` API. |

---

--------------------------------------------------------------------------------------------------------------------------


If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!

Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI

 YouTube: https://www.youtube.com/@learnservicenowwithravi
 LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/

Hi Ravi can we customize GlideModal Buttons instead of 'OK' and  'Cancel'

 

Regards,

APV Babu