Need a way to close g_modal.showFrame based on API results
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a month ago
This is my requirement.
There is a UI Action on HR Agent Workspace. When clicked, it invokes a UI Page (which has CSS/HTML for a custom loader) as a popup using g_modal.showFrame. The UI Action proceeds to do a GlideAjax and calls an API and gets the result. If API is successful, then the modal must be destroyed and form has to reload. If unsuccessful, the modal must be destroyed and an error message should be displayed.
Need help on below 2 points:
1. Close the modal automatically
2. Remove the white background in the modal.
Below is the code snippet:
UI Action Workspace script:
- Labels:
-
Human Resources Service Delivery
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
try this
function agentAssist() {
var caseSysId = g_form.getUniqueValue();
var ui_page_id = '<sys_id>';
var modal = g_modal.showFrame({
url: '/ui_page.do?sys_id=' + ui_page_id + '&caseid=' + caseSysId,
size: 'sm',
showClose: false
});
var ga = new GlideAjax('<SI>');
ga.addParam('sysparm_name', '<function>');
ga.addParam('sysparm_sys_id', caseSysId);
ga.getXML(function(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
// Close modal
if (modal) {
modal.destroy();
}
if (answer == 'Success') {
location.reload();
} else {
g_form.addErrorMessage('API failed. Please contact Administrator');
}
});
}
💡 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 || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
modal.destroy();this did not work. any other methods available?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
modal.destroy();This did not work. Are there any other methods?
