Jim Coyne
Kilo Patron
Included in the Developer Toolbox Update Set available on Share (link to Share in the post).

 

Along the same lines as the "GlideRecord Script" Tools, this tool will grab the individual values for the column from a List View when you group on a column:

 

JimCoyne_0-1683693577920.png

 

And the results appear in a popup window:

 

JimCoyne_1-1683693657062.png

 

There are a few formatting options available with this new custom UI Page.  The column name prefix has now been removed.

 

This makes it easy to grab the number of records that have the same data in a particular field.

There are 2 parts to the solution, a Context Menu that grabs the information and a new dedicated UI Page used to display the results:

 

Context Menu Configuration

Table: Global
Menu: List Header
Type: Action
Name: Grab Grouped Information
Order: 500,100
Action script:

 

 

 

 

(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.