Unable to run Script Include from sys_user_group_types table

NickUConnHealth
Tera Contributor

Hi All,

 

My org is setting up report views as a way for end users to see their own and related teams task items.

To do this we've set up a dashboard with a filter that allows them to display based on group types. The problem is the script include isn't working.

Checking the work in the Scripts - Background with a gs.log, I do see the SysIDs of the group types. But when running the same script include from the Group Types table I get 0 results. 

Snag_4b42bb91.png

 

 

Any ideas about the script or possibly a business rule?

 

function Test() {

var myID = gs.getUserID();
var myIDString = myID.toString();
var grpTypeList=[];
var gr = new GlideRecord("sys_user_grmember");
gr.addEncodedQuery("user=" + myIDString + "^group.typeISNOTEMPTY");
gr.query();

var i=0;
while(gr.next()) {
grpTypeList.push(gr.group.type);
}

return grpTypeList;
}

5 REPLIES 5

Sandeep Rajput
Tera Patron

@NickUConnHealth 

 

Try with the following script.

 

function Test() {

var myID = gs.getUserID();
var myIDString = myID.toString();
var grpTypeList=[];
var gr = new GlideRecord("sys_user_grmember");
gr.addEncodedQuery("user=" + myIDString + "^group.typeISNOTEMPTY");
gr.query();

var i=0;
while(gr.next()) {
grpTypeList.push(gr.group.type);
}

return grpTypeList.toString();
}

 

Hope this helps.

Ankur Bawiskar
Tera Patron

@NickUConnHealth 

you are calling it in wrong manner

SysId [IS ONE OF] javascript: Test();

I assume your report is on table "sys_user_group_type"

Update script include as this and it should be client callable. make the script include classless

function Test() {

    var myID = gs.getUserID();
    var grpTypeList = [];
    var gr = new GlideRecord("sys_user_grmember");
    gr.addEncodedQuery("user=" + myID + "^group.typeISNOTEMPTY");
    gr.query();
    while (gr.next()) {
        grpTypeList.push(gr.group.type.toString());
    }

    return grpTypeList.toString();
}

AnkurBawiskar_0-1738899670606.png

 

If my response helped please mark it correct and close the thread so that it benefits future readers.

NickUConnHealth
Tera Contributor
The issue was the following lines not being part of the script include.
 
var Test = Class.create();
Test.prototype = {
    getTest: function() {
 
 
However, I now can't get the script include to function for a non-itil user. I'm assuming there's a specific ACL or business rule that allows itil users to run script includes but prevents end users from doing the same. Does anyone know what it might be?

There's a business rule that stops the script from running for non-itil users, I don't know which one it is. 

 

My workaround was to add "gr.setWorkflow(false);" (see below) to get the script include to work. 

 

        gr.addEncodedQuery("user=" + myIDString + "^group.typeISNOTEMPTY");
        gr.setWorkflow(false);
        gr.query();
 
The new script include is as follows:
var GetType = Class.create();
GetType.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    getGroupTypes: function() {
        var myID = gs.getUserID();
        var myIDString = myID.toString();
        var grpTypeList = [];
        var gr = new GlideRecord("sys_user_grmember");
        //querying based on the user (in quotes) and the value (not in quotes)
        gr.addEncodedQuery("user=" + myIDString + "^group.typeISNOTEMPTY");
        gr.setWorkflow(false);
        gr.query();

        var i = 0;
        while (gr.next()) {
            i++;
            var strIteration = i.toString();
            //Display Group name and Group Type id.  
            gs.log(strIteration + " - Group Name: " + gr.group.name + " , Group Type:" + gr.group.type);
            //Add each Group Type to Array
            grpTypeList.push(gr.group.type);
        }
       
        var commaReturn=grpTypeList.join(",");
        return commaReturn;
    },

    type: 'GetType'
});