How can I create a scripted filters on user table.

Chandra18
Mega Sage

Hello experts,

I want to create a scripted filters on user table for showing user which having the "Itil" role.
I have taken the help from https://docs.servicenow.com/bundle/washingtondc-platform-user-interface/page/use/using-lists/task/t_...

I created below script include:

Chandra18_0-1713435829869.png


Please help on that.

Thank You!


1 ACCEPTED SOLUTION

Hi @Chandra18 ,

 

Please Remove all the content of the script and just keep below script or your script will also work 

 

function myFunction(){
        var arrUsers = [];
        gr = new GlideRecord('sys_user_has_role');
        gr.query('role', '282bf1fac6112285017366cb5f867469');//itil role sys_id
        while (gr.next()) {
            arrUsers.push(gr.user.toString());
        }
        return arrUsers;


}

 

 

AstikThombare_0-1713441123757.png

 

 

AstikThombare_1-1713441123800.png

 

 

 

    If my reply helped with your issue please mark helpful 👍 and correct ✔️ if your issue is resolved.

 

                         By doing so you help other community members find resolved questions which may relate to an issue they're having

 

 

Thanks,

 

Astik

 

View solution in original post

6 REPLIES 6

Hi @Chandra18 ,

 

Please refer below code 

 

 

gr.query('role.name', 'itil');

 

 

     If my reply helped with your issue please mark helpful 👍 and correct ✔️ if your issue is resolved.

 

                         By doing so you help other community members find resolved questions which may relate to an issue they're having

 

 

Thanks,

Astik

AndersBGS
Tera Patron

Hi @Chandra18 ,

 

Why not using the OOTB table sys_user_has_role with appropriate conditions? 

 

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.

 

Best regards

Anders

If my answer has helped with your question, please mark my answer as the accepted solution and give a thumbs up.

Best regards
Anders

Rising star 2024
MVP 2025
linkedIn: https://www.linkedin.com/in/andersskovbjerg/