We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

Two report needs to be built one for the requests raised by IT user and other is Non-IT user.

karishmanat
Tera Contributor

I have created two dynamic filters in ServiceNow:

  1. Member of IT Groups
  2. Not Member of IT Groups

In my instance, I have two IT groups:

  • Service Desk
  • Network

For example, Fred Luddy is a member of the Network group, so he is considered an IT user.

My requirement is:  If a user like Fred Luddy (who belongs to an IT group) raises/creates an RITM, that record should appear in the report.

To achieve this, I created a dynamic filter and used it in the report condition. However, even after configuring everything and trying multiple approaches, the report is still not showing the expected records.

I have also attached screenshots of my configuration.

 I need help understanding where the mistake is and why the records are not appearing, even though the user belongs to the IT group.

karishmanat_0-1782211305503.pngkarishmanat_1-1782211336302.pngkarishmanat_2-1782211360506.pngkarishmanat_3-1782211445012.png

 

 

2 ACCEPTED SOLUTIONS

Mariam_Ahmed
Tera Guru

 

Hi @karishmanat ,

I think the issue is with how the dynamic filter is configured. Before building a custom solution, I'd also recommend checking whether an out-of-the-box (OOTB) dynamic filter can satisfy your requirement.

If you need to proceed with a custom dynamic filter, update your Script Include to return an array of user  for example:

getGroupMembers: function() {
    var userList = [];
    var group1 = 'YOUR_GROUP_SYS_ID';
    var group2 = 'YOUR_GROUP_SYS_ID';

    var gr = new GlideRecord('sys_user_grmember');
    gr.addEncodedQuery('group=' + group1+ '^ORgroup=' + group2); 
    gr.query();

    while (gr.next()) {
        userList.push(gr.getValue('user'));
    }

    return userList; // Returns an array of user Sys IDs
},

type: 'GroupFilterUtil'

2. Configure the Dynamic Filter Option

Navigate to System Definition > Dynamic Filter Options and create a new record with the following values:

  • Label: IT Members

  • Script: new GroupFilterUtil().getGroupMembers();

  • Field type: Reference

  • Reference table: sys_user (since opened_by is a reference to the User table)

  • Available for filter: Checked

Save the record.

3. Apply the filter in the report

In the report condition builder, configure:

Opened by >is (dynamic) > IT Members

If you found this response useful, please mark it as Helpful and accept it as the Solution to help others with similar questions.


Best regards,

Mariam Ahmed.

Mariam Ahmed

ServiceNow Developer | Here to Learn, Here to Share

View solution in original post

Hi @karishmanat,

Add the following to the Dynamic Filter script:

 
new global.GroupFilterUtil().getGroupMembers()

Also, ensure that:

  • The Script Include is marked as Client Callable.
  • Sandbox is enabled for the Dynamic Filter.

 

Mariam_Ahmed_0-1782235885689.png

 

Expected Result: The dynamic filter should return the group members from the GroupFilterUtil Script Include and populate the filter correctly.

Mariam_Ahmed_1-1782235997548.png

 

If you found this response useful, please mark it as Helpful and accept it as the Solution to help others with similar questions.


Best regards,

Mariam Ahmed.

 

Mariam Ahmed

ServiceNow Developer | Here to Learn, Here to Share

View solution in original post

6 REPLIES 6

Mariam_Ahmed
Tera Guru

 

Hi @karishmanat ,

I think the issue is with how the dynamic filter is configured. Before building a custom solution, I'd also recommend checking whether an out-of-the-box (OOTB) dynamic filter can satisfy your requirement.

If you need to proceed with a custom dynamic filter, update your Script Include to return an array of user  for example:

getGroupMembers: function() {
    var userList = [];
    var group1 = 'YOUR_GROUP_SYS_ID';
    var group2 = 'YOUR_GROUP_SYS_ID';

    var gr = new GlideRecord('sys_user_grmember');
    gr.addEncodedQuery('group=' + group1+ '^ORgroup=' + group2); 
    gr.query();

    while (gr.next()) {
        userList.push(gr.getValue('user'));
    }

    return userList; // Returns an array of user Sys IDs
},

type: 'GroupFilterUtil'

2. Configure the Dynamic Filter Option

Navigate to System Definition > Dynamic Filter Options and create a new record with the following values:

  • Label: IT Members

  • Script: new GroupFilterUtil().getGroupMembers();

  • Field type: Reference

  • Reference table: sys_user (since opened_by is a reference to the User table)

  • Available for filter: Checked

Save the record.

3. Apply the filter in the report

In the report condition builder, configure:

Opened by >is (dynamic) > IT Members

If you found this response useful, please mark it as Helpful and accept it as the Solution to help others with similar questions.


Best regards,

Mariam Ahmed.

Mariam Ahmed

ServiceNow Developer | Here to Learn, Here to Share

I have created everything as per your instructions, but I am still not able to fetch any records in the report. I will attach the screenshot for your reference.
karishmanat_0-1782231443520.pngkarishmanat_1-1782231491318.pngkarishmanat_2-1782231515976.png

 

Hi @karishmanat,

Add the following to the Dynamic Filter script:

 
new global.GroupFilterUtil().getGroupMembers()

Also, ensure that:

  • The Script Include is marked as Client Callable.
  • Sandbox is enabled for the Dynamic Filter.

 

Mariam_Ahmed_0-1782235885689.png

 

Expected Result: The dynamic filter should return the group members from the GroupFilterUtil Script Include and populate the filter correctly.

Mariam_Ahmed_1-1782235997548.png

 

If you found this response useful, please mark it as Helpful and accept it as the Solution to help others with similar questions.


Best regards,

Mariam Ahmed.

 

Mariam Ahmed

ServiceNow Developer | Here to Learn, Here to Share

Initially, I used hardcoded group sys_ids in my Script Include, and the functionality was working as expected.
Later, I replaced the hardcoded values by storing the group sys_ids in a system property (ITmembers.group_ids) to make the solution more maintainable.
However, after updating the script to fetch the values from the system property, the Script Include is no longer working as expected.
karishmanat_3-1782469693450.png

 

karishmanat_1-1782469434061.pngkarishmanat_2-1782469641067.png