Script Include in Report Filter Condition Not Working

Kieron Jones
Giga Expert

Hi Community!

I have been struggling with some script include calls when writing a report on the discovery_device_history table.

I am trying to provide the sys_id for the latest discovery_status record for a given IP address from the discovery_device_history table. Filters below.

find_real_file.png

For each Discovery Device History row, I need to pass in the source column value to the script include and have it return the sys_id for the latest discovery_status entry.

My expected script include call does not work:

javascript: new DiscoveryLatestStatusRow().GetStatusRow(discovery_device_history.source);

This script include call does work, but it's not variable, as the source value is hardcoded:

javascript: new DiscoveryLatestStatusRow().GetStatusRow("10.118.100.251");

This does not work either, trying to use the "current" record:

javascript: new DiscoveryLatestStatusRow().GetStatusRow(current.source);

Nor does this:

javascript: new DiscoveryLatestStatusRow().GetStatusRow(source);

My script include is simple:

find_real_file.png

I'm sure this is possible, any help on the call or perhaps re-org of the script (if needed) would be greatly appreciated!

Thanks

1 ACCEPTED SOLUTION

Adam Stout
ServiceNow Employee

Script run to generate the query, they do not run on the records themselves.  There is no "current".  That is why the constant works but a variable doesn't.  You can't force a correlated subquery or change the join conditions based on the where conditions.

I'm not sure how this will work here, but in similar use cases, I add a field to discovery_status "Last Discovery" that is a reference to discovery_device_history and a BR on discovery_device_history that when the CI changes, it updates the reference on discovery_device.

My real use case is pm_project and status_report, but perhaps that would work here.  

View solution in original post

5 REPLIES 5

Ashutosh Munot1
Kilo Patron

Hi,

What you should do is as follow:

1) Create a script include as below:

find_real_file.png

2) Call it into filter as below:

find_real_file.png

 

Thanks,
Ashutosh

Kieron Jones
Giga Expert

Thank you Ashutosh,

The script that I posted above, does actually work in its current format, with the IP / Source as specified in the 2nd call in my above post; I know it may not be the most efficient code!

What I am after, is having the discovery_device_history.source from each record read, passed into the script and the sys_id for the latest record returned; this will remove any duplicates.

In effect, having the hard coded value in the call, change on each record read from the discovery_device_history table.

Hi,

the issue is the script won't trigger for each record in that table where you are filtering. You can only trigger it once so it will return all records as per query, so bit hard to change filter. But duplication has to be handled in script include instead of passing value from filter.

Thanks,
Ashutosh

Adam Stout
ServiceNow Employee

Script run to generate the query, they do not run on the records themselves.  There is no "current".  That is why the constant works but a variable doesn't.  You can't force a correlated subquery or change the join conditions based on the where conditions.

I'm not sure how this will work here, but in similar use cases, I add a field to discovery_status "Last Discovery" that is a reference to discovery_device_history and a BR on discovery_device_history that when the CI changes, it updates the reference on discovery_device.

My real use case is pm_project and status_report, but perhaps that would work here.