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.

Advanced Reference Qualifier with Script Include not working

Vinicius Luz
Tera Expert

Hello,

 

I have a reference field pointing to the sys_user table called "GP Approvers" attached to a MRVS on the portal

I need it to filter its choices based on a group, to show only this group members. Here's my code

 

Script Include:

getGPapprovers: function() {

        var users = [];
        var gr = new GlideRecord("sys_user_grmember");
        gr.addQuery("group", "2d5b43881b864110d9ad0dcbe54bcb5c");
        gr.query();
        while (gr.next()) {
            users.push(gr.getValue("user"));
        }

        return 'sys_idIN' + users.join();
    },

 

Field:

find_real_file.png

 

In my understanding this is properly set, unless I'm not seeing the error. Or even the MRVS doesnt accept this setup ...

Whats wrong ?

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

are you using this in scoped app?

if yes then getValue() won't work

use this

getGPapprovers: function() {

        var users = [];
        var gr = new GlideRecord("sys_user_grmember");
        gr.addQuery("group", "2d5b43881b864110d9ad0dcbe54bcb5c");
        gr.query();
        while (gr.next()) {
            users.push(gr.user.toString());
        }

        return 'sys_idIN' + users.join();
    },

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

6 REPLIES 6

Shakeel Shaik
Giga Sage
Giga Sage

Hi @Vinicius Luz 

 

I want to know, How you are passing the group sys_id.

 

is group sys_id is static or dynamic??

 

Please check and let us know.

Thanks 🙂

Thanks,
Shakeel Shaik 🙂

Hitoshi Ozawa
Giga Sage
Giga Sage

Try converting the user to String when pushing.

users.push(gr.getValue("user").toString());

Shakeel Shaik
Giga Sage
Giga Sage

 

Hi @Vinicius Luz 

 

Here I updated the script.

 

getGPapprovers: function() {

        var users = [];
        var gr = new GlideRecord("sys_user_grmember");
        gr.addQuery("group", "2d5b43881b864110d9ad0dcbe54bcb5c");
        gr.query();
        while (gr.next()) {
            users.push(gr.getValue("user"));
        }

       var vQuery  = 'sys_idIN' + users;

       return JSON.stringify(vQuery);
    },

 

 

Please check and let us know.

Thanks 🙂

Thanks,
Shakeel Shaik 🙂

Shakeel Shaik
Giga Sage
Giga Sage

Hi @Vinicius Luz 

 

Use this script in Your Reference Qualifier.

sys_idINjavascript: new CriacaoUtils().getGPapprovers();^EQ

Please check and let me know.

Thanks 🙂

Thanks,
Shakeel Shaik 🙂