"Grab Grouped Information" Tool
Import
·
Oct 15, 2018
·
article
(function() {
try {
var groupedItems = []; //will add each item to this Array
var allElements = $$("span.list_group"); //get all the Grouped items
var element = "";
for (var i = 0; (element = allElements[i]) != null; i++) {
//loop through to get each one individually, stripping off the field name
var item = element.innerHTML;
var withoutLabel = item.match(/: (.*)/)[1]; //drop the column label
groupedItems.push(withoutLabel);
}
//old version
//simply uncomment this section and comment out the next one to use the old version of the floating GlideDialogWindow
/*
var gdw = new GlideDialogWindow("u_fpc_simple_copy_paste");
gdw.setTitle(getMessage("u_fpc_grab_grouped_information.modal.title"));
gdw.setPreference("sysparm_text", encodeURIComponent(groupedItems.join("\n"))); //encode the string so it can be passed to the UI Page properly and then decoded there
gdw.render();
*/
//new version
//uses a new dedicated UI Page that includes some formatting options
//to use a moveable GlideDialogWindow, uncomment the next line and then comment the GlideModal line
//var popup = new GlideDialogWindow("u_fpc_grab_grouped_information");
var popup = new GlideModal("u_fpc_grab_grouped_information");
try {
popup.setBackdropStatic(true); //remain open when user clicks outside of the window, but only used with GlideModal windows
} catch(err) {}
popup.setTitle(getMessage("u_fpc_grab_grouped_information.modal.title"));
popup.setPreference("sysparm_text", encodeURIComponent(groupedItems.join("\n")));
popup.setPreference("sysparm_message", encodeURIComponent(getMessage("u_fpc_grab_grouped_information.modal.instructions")));
popup.setWidth(600);
popup.render();
} catch (err) {}
})();
I've included XML files for the Context Menu, UI Page and the UI Messages that are used in both so you can just import them into your instance. As always, try it out in your company's development instance first, or better yet, your own personal development instance.
Updated May 10, 2023: Added a new UI Page specifically for this tool instead of using the shared "u_fpc_simple_copy_paste" UI Page, although there is still code within the Context Menu to switch back if you so desire. The condition on the Context Menu has been removed so it is now available to all users.
View original source
https://www.servicenow.com/community/developer-blog/quot-grab-grouped-information-quot-tool/ba-p/2269191