- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2019 02:59 AM
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.
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:
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
Solved! Go to Solution.
- Labels:
-
Reporting
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2019 09:28 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2019 05:58 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2019 08:21 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2019 10:44 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2019 09:28 AM
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.
