Hide 'Add All' option when relating incident to problem
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2024 09:05 PM
Hello, community
I'm attempting to follow this post to remove the 'Add All' option from the 'Add Incident' modal that appears when clicking 'Add' on the Incident related list for Problem records.
I believe this is still possible using a similar method, but GlideModalv3 functions differently than GlideOverlay and does not seem to provide any new methods to remove this option. This is the full script from the 'Add' UI Action, including my additional function to remove the button:
function openIncidentList(){
var gajax = new GlideAjax("LKQ_BulkAddIncidents");
gajax.addParam("sysparm_name","getURL");
gajax.addParam("sysparm_sys_id", g_form.getUniqueValue());
gajax.addParam("sysparm_parent_table", g_form.getTableName());
gajax.getXMLAnswer(openListModalIncident);
}
function openListModalIncident(url){
//render the modal
var incModal = new GlideModal('incident_add_records');
incModal.setTitle(getMessage("Add Incidents"));
incModal.setWidth(1200);
incModal.setAutoFullHeight(true);
incModal.on('beforeclose', function(){
refreshRelatedIncidents();
});
ScriptLoader.getScripts('/scripts/incident/glide_modal_accessibility.js', function() {
incModal.template = glideModalTemplate;
incModal.renderIframe(url, function(event) {
glideModalKeyDownHandler(event, incModal.getID());
removeAddAll();
});
});
var link = document.createElement('link');
link.rel = 'stylesheet';
link.href = 'styles/incident_glide_modal.css';
document.head.appendChild(link);
}
function refreshRelatedIncidents() {
GlideList2.get(g_form.getTableName() + '.' + g_list.getRelated()).setFilterAndRefresh('');
}
function removeAddAll(){
var iframe = document.getElementsByClassName("modal-content")[0];
if(!iframe){
return;
}
var addAll = $j(iframe).contents().find("#add_all"); //Find the Add All button
$j(addAll).remove(); //Remove the Add All button
}
However, this causes the modal to stall while loading. There doesn't seem to be a 'gb_iframe' element rendered by GlideModal as was used in the previous solution. There is a modal-content element in the modal that's created, but it does not match what I see when checking the console after the modal is rendered and appears on screen. Is there an updated way to accomplish this? I'm aware that the modal content is locked down and can only be accessed by ServiceNow, but I need to remove this option and am trying to do so in the least intrusive way possible.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-25-2024 02:06 PM
Hi @Patrick Farr
I have a workaround for this. When clicked Add All, a Pop up comes to confirm. It is the UI Page add_all_incident_confirmation.
So, I modifying the Add option in the Add All pop could help you.
Commenting the default message and buttons and hardcoding that this is disabled.
HTML code of UI Page.
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<g:evaluate jelly="true">
<!--
var msg = gs.getMessage('Associating all {0} Incidents with this Problem will be done as a background task', ${RP.getWindowProperties().get('count')});
if(${RP.getWindowProperties().get('count')} == 1) {
msg = gs.getMessage('Associating the Incident with this Problem will be done as a background task');
}
-->
var msg = gs.getMessage('Adding all incidents is disabled');
</g:evaluate>
<div style="text-align:left;">
<div>${msg}</div>
<div align="right" class="modal-footer">
<!-- <g:dialog_buttons_ok_cancel ok="return ok()" cancel="return cancel()" ok_type="button" ok_style_class="btn btn-primary" ok_text="${gs.getMessage('Add')}" cancel_type="button"/> -->
</div>
</div>
</j:jelly>
If this information helps you, Kindly mark it as Helpful.
Regards,
Najmuddin.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-25-2024 10:02 PM
Hi, Najmuddin
I really like this approach, but it looks like the add_all_incident_confirmation popup was removed from the 'Add All' button at some point in previous ServiceNow versions. When clicking it now, the modal simply displays the loading symbol until all the records are added. Is it possible to force this popup to come up again so that we can edit its behavior? Or would it be possible to force the GlideModal object to recognize a different addAll(); function than the one already defined? I have yet to successfully influence anything in the incident_add_records UI page, so I'm not immediately sure how to go about this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-25-2024 11:19 PM
I was able to determine the issue with my original method and correct the script for anyone having a similar problem. By using querySelectorAll("iframe[title='Add Incidents']"), I was able to find the correct iframe and hide the button. This script successfully hides the 'Add All' button after it's rendered.
function openIncidentList(){
var gajax = new GlideAjax("BulkAddIncidents");
gajax.addParam("sysparm_name","getURL");
gajax.addParam("sysparm_sys_id", g_form.getUniqueValue());
gajax.addParam("sysparm_parent_table", g_form.getTableName());
gajax.getXMLAnswer(openListModalIncident);
}
function openListModalIncident(url){
//render the modal
var incModal = new GlideModal('incident_add_records');
incModal.setTitle(getMessage("Add Incidents"));
incModal.setWidth(1200);
incModal.setAutoFullHeight(true);
incModal.on('beforeclose', function(){
refreshRelatedIncidents();
});
ScriptLoader.getScripts('/scripts/incident/glide_modal_accessibility.js', function() {
incModal.template = glideModalTemplate;
incModal.renderIframe(url, function(event) {
glideModalKeyDownHandler(event, incModal.getID());
removeAddAll();
});
});
var link = document.createElement('link');
link.rel = 'stylesheet';
link.href = 'styles/incident_glide_modal.css';
document.head.appendChild(link);
}
function refreshRelatedIncidents() {
GlideList2.get(g_form.getTableName() + '.' + g_list.getRelated()).setFilterAndRefresh('');
}
function removeAddAll(){
var iframe = document.querySelectorAll("iframe[title='Add Incidents']");
if(!iframe){
return;
}
var addAll = $j(iframe).contents().find("#add_all");;
$j(addAll).hide();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2025 01:15 PM