UI page should redirect to current list view / ui page after alert dialog closes - not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2023 10:58 AM - edited 06-26-2023 09:47 AM
Hello All,
I have a UI page that performs mass updates to records selected in a list view through a list choice UI action (there are two list views it appears on). On the UI page is a checkbox field "Validation Complete" (id=validation_complete). If this field is unchecked and the user clicks to submit the UI page, they should receive a popup alert advising them to select the checkbox, and when they click OK on the alert dialog page, it should redirect them back to the list view (where the records they have selected to update are still checked) and the open UI page on top (with their populated fields still populated). Essentially bringing them back to the place they were at before clicking to submit the UI page.
To achieve this, I created two functions in my client script to: 1.) gather the list of selected records, and 2.) wait for the user to click OK on the alert dialog window and redirect them back to the list with the original records still selected. The problem is that neither are working.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2023 07:30 AM - edited 03-11-2023 07:31 AM
Hi @Still Learning ,
Below are a few finding
1. The 'c' variable used in the 'massUpdates()' function is not defined before it is used in the else block. It needs to be defined before it can be assigned a value.
2. The 'addEventListener()' method used in the 'massUpdates()' function needs to be called on the 'okButton' element after it has been created. Currently, it is called immediately after the alert is displayed, which may result in the okButton element not being available yet.
3.The 'getSelectedRecords()' function checks if the 'validation_complete' checkbox is checked before getting the selected records. This means that if the checkbox is unchecked, it will return an empty array regardless of the selected records. Instead, the 'getSelectedRecords()' function should first check if the 'validation_complete' checkbox is checked, and only then get the selected records.
Here's a revised version of the code
function massUpdates() {
var gdw = GlideDialogWindow.get();
var validate = gel('validation_complete').checked;
var c = gel('sysparm_complete');
if (validate) {
c.value = "true";
GlideDialogWindow.destroy();
} else {
alert("Confirm that validation is complete by checking the box and agreeing to the confirmation message.");
var okButton = document.getElementsByClassName('alertdialog-basic')[0].getElementsByClassName('btn-primary')[0];
okButton.addEventListener('click', function() {
var newRecords = getSelectedRecords();
if (newRecords.length > 0) {
var currentListViewURL = window.location.href.split('?')[0];
var sysparmQuery = "sysparm_query=sys_idIN" + newRecords.join(',');
var uiPageURL = gdw.getParentFrame().location.href;
var uiPageEncodedURL = encodeURIComponent(uiPageURL);
var redirectURL = currentListViewURL + '?' + sysparmQuery + '&sysparm_ui_page=' + uiPageEncodedURL;
window.location.href = redirectURL;
}
});
c.value = "false";
return false;
}
return true;
}
function getSelectedRecords() {
var completed = gel('validation_complete').checked;
var newRecords = [];
if (completed) {
var selected = gel("sys_original_checkbox");
for (var i = 0; i < selected.length; i++) {
if (selected[i].checked) {
newRecords.push(selected[i].value);
}
}
}
return newRecords;
}
function onCancel() {
GlideDialogWindow.get().destroy();
return false;
}
Regards,
Shravan.
Please mark as helpful and correct answer if this helps you
Shravan
Please mark this as helpful and correct answer, if this helps you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2023 04:32 PM
Hello @Sai Shravan
Thank you SO much for your reply to my post!! Unfortunately, after implementing the suggestions you've provided to me, the code is still not working. It redirects back to the list view after clicking OK on the alert dialog popup window, but does not leave the UI page open with fields populated, nor does it keep the selected records from the list view. It essentially is treating the OK button on the alert dialog popup window as an action.cancel(); function ... Do you see any other issues with my code that will need to be adjusted to help me meet the clients stated requirements? Please advise.