Use script includes with Performance Analytics

Amy13
Tera Contributor

Can script includes be used with Performance Analytics? I'm trying to use a dynamic filter on the indicator source and it calls a script include. In the "Preview" button I can see the filter is working -- however, when I run the data jobs, the filter doesn't work. Has anyone experienced something like this?

7 REPLIES 7

Punit S
Giga Guru

Yes, script includes can be used with Performance Analytics. In fact, script includes are a powerful tool in ServiceNow and can be used in many areas, including Performance Analytics.

If you're experiencing an issue where the filter is not working in the data jobs, it's possible that the issue is related to the timing of when the script include is being called.

When you preview an indicator, the filter is applied at that moment and the data is immediately refreshed. However, when you run a data job, the filter may not be applied until later in the process. This can result in the data being fetched before the filter is applied, which could explain why the filter isn't working in the data jobs.

To resolve this issue, you could try one of the following:

  1. Use a static filter: Instead of using a dynamic filter that relies on a script include, you could use a static filter that is not dependent on any script includes. This way, the filter will be applied consistently and reliably in both the preview and the data jobs.

  2. Ensure the script include is loaded before the data job runs: You can ensure that the script include is loaded before the data job runs by adding a "load" statement for the script include in the data job. This will ensure that the script include is available when the data is fetched and the filter is applied.

  3. Check the script include for errors: It's possible that there's an error in the script include that is preventing the filter from working in the data jobs. Check the script include for any syntax errors or other issues that could be causing the problem.

If none of these solutions work, it may be necessary to further troubleshoot the issue or seek assistance from ServiceNow SME or a ServiceNow Partner.

 

Please mark my answer correct/helpful in case it adds value and moves you a step closer to your desired ServiceNow solution goal. 

Thanks,
Punit

Amy13
Tera Contributor

Hi Punit,

 

Thanks so much for responding to my post!! Could you also take a look at my materials and let me know if you have any additional tips?

 

 

Amy13_0-1680555079301.png

This is my indicator source. The table is a custom database views table (will that impact the script include's ability to work correctly?) and in the conditions, the first line is my dynamic filter that's calling my script include called "notServiceDeskCaller". The goal is to only get records where the incident's caller_id is not a member of a particular group, along with some other conditions. As you can see, I should be getting 3 records returned for today, which is correct. I've also looked at what I should be getting for last month for testing purposes once I run the jobs, and the preview tells me 3 for March as well.

 

Amy13_1-1680555225906.png

Amy13_2-1680555260893.png

 

And this is my script include. When I run my historical job, for the month, unfortunately I do not see the 3 records I was looking for in my Scoresheet, even though I see it in the preview. Any ideas why my script include isn't working? Thank you!

 

 

Based on the script include code you provided, it seems that the issue may be with the query you're using to filter out incidents whose caller is a member of a certain group. Specifically, it looks like you're using an encoded query to filter on the  incident_caller_id field, which may not work as expected if the field is not indexed or if the encoded query syntax is incorrect.

To troubleshoot this issue, I would suggest the following:

  1. Check the script include's debug logs to see if there are any errors or exceptions being thrown when the script runs.

  2. Verify that the group ID you're using in the encoded query is correct and that it corresponds to the correct group in your instance.

  3. Test the encoded query in the Incident table directly to see if it returns the expected results. If it does not, adjust the query until it returns the expected results.

  4. If the encoded query is working correctly, try running the script include with a simplified query that only filters on the  incident_caller_id field to see if the issue is with the other conditions in the query.

  5. If none of the above steps work, you may want to consider reaching  out to  ServiceNow SME or your ServiceNow services partner architect for further assistance.

As for the custom database views table you're using in your indicator source, it should not impact the script include's ability to work correctly as long as the table and fields you're querying are correctly configured and accessible in your instance.

 

Please mark my answer correct/helpful in case it adds value and moves you a step closer to your desired ServiceNow solution goal. 

Thanks,
Punit

 

Amy13
Tera Contributor

Punit, can you explain how I would go about doing this?

 

"Ensure the script include is loaded before the data job runs: You can ensure that the script include is loaded before the data job runs by adding a "load" statement for the script include in the data job. This will ensure that the script include is available when the data is fetched and the filter is applied." 

 

I am not sure what you mean by loading a script?