Condition Based on User Group in Scheduled Report Email or Report

Weverton
Tera Contributor

HI guys.

 

I would like to know if it's possible to set a condition in the Scheduled Email of Report or in the Report,  based on the groups the user belongs to. 

 

In my use case, I need the user to not receive the report if they are part of a specific group.

 

 

Weverton_0-1778514899769.png

 

 

4 REPLIES 4

Christopher Sik
Mega Guru

Can you add some more context this question?

Are you trying to send the report to members of one or more specific groups? If that's the case, you would use the Groups filter (pictured in the top half of your screenshot) to select the desired groups. Then the scheduled report would get sent to the members of those groups.

I forgot about that part. I need the user to not receive the report if they are part of a specific group.

I don't believe there is a no code way to exclude members of a specific group using the scheduled report form fields. But there is a the conditional check box on the form. If you check that, a condition field will appear that allows you to add a script which could achieve your goal. 

You could also create a scheduled job that adds users to a report group based on certain conditions. For example: Add all itil users who do not have a membership in Group A to Group B. This could be setup to run daily, hourly, etc based on the turnover frequency in your organization. 

Then set Group B as recipient group on your scheduled report.

Tanushree Maiti
Giga Patron

Hi @Weverton 

To exclude users in a specific group from a Scheduled Report in ServiceNow, use the Conditional checkbox on the scheduled report and script it to check for group membership. 

  1. Navigate to Reports > Scheduled Reports.
  2. Open your report.
  3. Check the Conditional checkbox.
  4. In the Condition script field, use a script 
Sample Script is given below:
answer = checkCondition();function checkCondition() {
      var groupToExclude = '<sys_id_of excluded_group>'; 
     var isMember = gs.getUser().isMemberOf(groupToExclude);
        if (isMember) {
        return false;
    }
    return true;
}
Update code as per your requirement.
 
 
Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti