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

 

Another entry to the useful tools series ("GlideRecord Script" Tools, "Grab Grouped Information" Tool, "View Data to Preserve" Tool and "Clear User Settings" Tool), here is the "Create a Module from this Query" tool.   It came to be because I was searching through some records and thought that I really should add a Module for the admins and then I wished I could just turn this query into a Module.

 

A UI Context Menu, it allows you to create a module from a List View that you have filtered down (or not) to a specific set of criteria.   Just go to a list of records, filter it down to what records you want to see and then select the "Create a Module from this Query" menu item from the List View's header context menu (it only appears for users with the "admin" role):

 

find_real_file.png

 

You'll get a confirmation dialog...

 

find_real_file.png

 

...and once you confirm, the Module record will be created and you'll be redirected to the record to finish configuring it:

 

_Screenshot_003.png

 

It creates the record with the table name, view and condition(s).   Add the Title, the Application menu it should show up in, the Order, etc... and you are all set.   I tried to write it without creating the record first, but the Filter field would not default properly past the first condition.

 

 

Here's the details for the UI Context Menu record you need to create:

Table:      Global [global]

Menu:       List Header

Type:       Action

Name:       Create a Module from this Query

Order:      500,100

Active:     checked

Condition:  gs.hasRole("admin")

Action Script:

 

 

 

(function() {
    //skip the creation unless confirmed by the user
    if (!confirm(getMessage("u_fpc_create_module_from_query.confirm")))
        return;

    //create the record
    var gr = new GlideRecord("sys_app_module");
    gr.initialize();
    gr.link_type = "LIST";
    gr.name = g_list.tableName;
    gr.filter = g_list.getQuery();
    gr.view_name = g_list.getView();
    var newModule = gr.insert();

    if (newModule) {
        //redirect to the new record
		var gUrl = new GlideURL("sys_app_module.do");
		gUrl.addParam("sys_id", newModule);
		g_navigation.open(gUrl.getURL());
    } else {
		var gm = new GlideModal("u_fpc_modal_simple_alert");
		try {
			gm.setBackdropStatic(true);  //remain open when user clicks outside of the window.  Can omit if you do not care about this
		} catch(err) {}
		gm.setWidth(400);
		gm.setTitle(getMessage("u_fpc_create_module_from_query.title"));
		gm.setPreference("sysparm_message", encodeURIComponent(getMessage("u_fpc_developer_toolbox.message.error.unknown")));
		gm.render();
    }

})();

 

 

 

 

You will not use it often, but it's worth having for those times you do need it.

 

I've attached an XML file so you can just import it into your instance. As always, try it out in your company's development instance first, or better yet, your own personal development instance.

 

Updated June 13, 2022:

- Uses the "Simple Modal Alert" UI Page to show any error message

1 Comment