Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Setting list module fixed query with script include

Al_Andrea
Tera Expert

Hi.

 

I need to apply a fixed (preferrably) query to a module that displays a list of records in a scoped application.

Is it possible use a script include to build the query of a module?

I've seen on the instance some OOTB cases in which this was done with a module of type List of record with a script include call in the arguments but I haven't been able to do it myself.

Has someone done this before or is there another solution?

I could do this with a before query business rule but I would rather not.

 

This is the code in the script include to build the query.

getCurrentUserGroups: function() {
        var groups = [];
        var grGroupMember = new GlideRecord("sys_user_grmember");
        grGroupMember.addEncodedQuery("user=" + gs.getUserID() + "^group.nameSTARTSWITHmy group prefix");
        grGroupMember.query();
        while (grGroupMember.next()) {
            groups.push(grGroupMember.group());
        }
        return groups.toString();
    },

    filterForGroups: function() {
		var groups = this.getCurrentUserGroups();
        return "assignment_groupIN" + groups;
    },

I know there is a Dynamic filter for the user's groups but that adds every group to the query not only the application ones. 

 

In the module I have tried to invoke this script inlcude with every kind of syntax but I wasn't able to execute it.

1 ACCEPTED SOLUTION

Al_Andrea
Tera Expert

After checking the "Snadbox enabled" checkbox on my client callable script include record I was able to succesfully use it in the module.

View solution in original post

5 REPLIES 5

JenniferRah
Mega Sage
Mega Sage

In the filter for the module, did you try to select Assignment Group IS ONE OF and then do something like this?

javascript: getCurrentUserGroups();

You would need to change your script to just include the list of sys_ids, but it might work.

Brad Bowman
Kilo Patron
Kilo Patron

I'm sure there's a way to get this to work with the correct argument, or maybe a new dynamic filter, but it seems like a simple filter might work in this case.

BradBowman_0-1732735317710.png

 

Al_Andrea
Tera Expert

In the end I just used a before query business rule

If you don't want that to apply everywhere, you could create a Database View with just the one table, then use the Database View as the table for the before query Business Rule and module.