i have created a dashboard and report on alm_hardware table, my requirement is that i want to show the report count of duplicate serial number on hardware table. if no duplicates on alm_hardware then show 0 on dashboard
Assistant
User
in servicenow
Assistant
To accomplish the task you outlined, you'll need to create a query that counts the number of duplicate serial numbers in the alm_hardware table. Given that you are aiming to display this information in a report and then show it in a dashboard, I'll walk you through the steps to achieve this:
Step 1: Create the Query
First, you need a SQL query to identify duplicate serial numbers in the alm_hardware table:
sql
SELECT
COUNT(*) AS duplicate_count
FROM
(SELECT
serial_number
FROM
alm_hardware
GROUP BY
serial_number
HAVING
COUNT(serial_number) > 1) AS duplicates;
This query will:
Group the records by serial_number.
Find the groups having more than one record (indicating duplicates).
Count the number of such groups.
Step 2: Create the Report
Depending on the BI tool you are using (e.g., Power BI, Tableau, or even a custom web dashboard), you'll need to create a new report using the above query.
For instance, if you are using a SQL-based BI tool:
Create a New Report: In your BI tool, create a new report and use the custom SQL query capability if available.
Query Configuration: Input the above query in the SQL editor of the tool to set up the data source.
Step 3: Configure the Dashboard
Add the newly created report to your dashboard:
Add a Widget or Tile: Most BI tools have the concept of widgets or tiles you can add to your dashboard.
Configure the Data Source: Set the data source of the widget/tile to be the report you just created.
Display the Count: Ensure your widget/tile is configured to display the duplicate_count result from your query.
Handling No Duplicates Scenario
You will also want to handle the scenario where no duplicates are found and ensure the dashboard reflects "0". The provided query will inherently do this as it will return 0 duplicates when no groups with more than one serial_number are found.
Example Dashboard Configuration
If you are using Power BI, for instance:
Import Data: Import the result of the SQL query into Power BI.
Visualization: Use a card or KPI visualization to display the duplicate_count.
Title & Formatting: Name the card appropriately, like "Duplicate Serial Numbers Count".
For other BI tools like Tableau:
Custom SQL Input: Go to the data source tab, use the custom SQL option, and paste the query.
Create Sheet: Create a new sheet with the SQL result showing the data.
Visualization: Use appropriate visualization (card, text, etc.) to display the result.
Add to Dashboard: Drag this sheet into your main dashboard layout.
Conclusion
With these steps, you should be able to achieve a dashboard that displays the count of duplicate serial numbers in the alm_hardware table, showing 0 if no duplicates are present.
In ServiceNow, you can achieve this by creating a report and then displaying it in a dashboard. Here is a step-by-step guide to help you.
Step 1: Create a Report
Navigate to Reports: In ServiceNow, go to Reports > Create New.
Set Up Report:
Name: Give your report a meaningful name, like "Duplicate Serial Numbers in Hardware".
Source Type: Select Table.
Table: Choose alm_hardware.
Filter and Group By:
Filter: Add a condition to filter out the serial numbers and only focus on duplicates.
Field: serial_number
Condition: is not empty
Group By:
Click on the Group By button and select serial_number.
This will group all records by the serial number.
Set Aggregation:
Click on the Aggregation icon.
Choose the Count aggregation on the serial_number field.
Add Having Clause:
Find the Having option (usually under advanced settings) if it's available.
Add a condition to include only groups having more than one item:
Aggregation count of serial_number > 1
Step 2: Create a Metric Definition (Optional)
If grouping and having options are limited in reports, consider creating a metric definition:
Navigate to MetricBase > Definitions > New.
Define a metric that counts the duplicate serial_number through a script or using aggregations.
Step 3: Display in a Dashboard
Navigate to Dashboards: Go to Self-Service > Dashboards.
Create a New Dashboard or select an existing one.
Add a Performance Analytics Widget:
Add a new widget by clicking on the Add Content button.
Choose Performance Analytics.
Select the report you created.
Adding Conditional Logic
In ServiceNow, direct support for a conditional display like 0 if no duplicates might need additional script logic:
Script Include:
Create a Script Include that runs the SQL query and returns the result.
Navigate to System Definition > Script Includes > New.
Here’s a sample Script Include:
javascript
var DuplicateSerialReport = Class.create();
DuplicateSerialReport.prototype = {
initialize: function() {},
getDuplicateCount: function() {
var duplicateCount = 0;
var gr = new GlideAggregate('alm_hardware');
gr.addAggregate('COUNT', 'serial_number');
gr.groupBy('serial_number');
gr.addHaving('COUNT', 'serial_number', '>', '1');
gr.query();
if (gr.next()) {
duplicateCount = gr.getAggregate('COUNT', 'serial_number');
}
return duplicateCount;
},
type: 'DuplicateSerialReport'
};
Business Rule/Background Script:
Use the Script Include in a business rule or background script to update a field that you can report against.
Final Display
Ensure your report widget is configured properly to pull from the DuplicateSerialReport result.
In your dashboard, the widget will show the appropriate number of duplicates or 0.
By following these steps, you should be able to create a functional report in ServiceNow that checks for duplicate serial numbers and displays the count in a dashboard, with a fallback to 0 when no duplicates exist.