-
Notifications
You must be signed in to change notification settings - Fork 678
Add Scheduled Job script to auto-refresh dashboard daily #1590
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Automatic Dashboard Refresh Script for ServiceNow | ||
|
||
This script, designed for ServiceNow, automatically refreshes a specified dashboard daily at 12:00 AM. By creating a Scheduled Job with this script, users can ensure their dashboard data is updated without manual intervention. | ||
|
||
## Overview | ||
|
||
ServiceNow’s Scheduled Jobs feature allows you to run server-side scripts at specified intervals. This script uses the `pa_dashboards` table to update the `last_refreshed` field on a given dashboard record, simulating a refresh. | ||
|
||
## Prerequisites | ||
|
||
- Access to ServiceNow with permissions to create and run Scheduled Jobs. | ||
- The `sys_id` of the dashboard you want to refresh. | ||
|
||
## Setup Instructions | ||
|
||
1. **Navigate to Scheduled Jobs**: | ||
- Go to **System Definition > Scheduled Jobs** in ServiceNow. | ||
|
||
2. **Create a New Scheduled Job**: | ||
- Set the job to run at **12:00 AM** daily. | ||
|
||
3. **Add the Script**: | ||
- Copy and paste the script below into the Scheduled Job’s script field. | ||
- Replace `YOUR_DASHBOARD_SYS_ID` with the `sys_id` of the dashboard you want to refresh. | ||
|
||
4. **Save and Activate the Job**: | ||
- Ensure the job is active and will repeat daily. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Define the sys_id of the dashboard you want to refresh | ||
var dashboardSysId = 'YOUR_DASHBOARD_SYS_ID'; | ||
|
||
// Function to simulate the dashboard refresh | ||
function refreshDashboard(dashboardSysId) { | ||
// Use the Service Portal widget for dashboards to refresh them | ||
var dashboardGR = new GlideRecord('pa_dashboards'); | ||
if (dashboardGR.get(dashboardSysId)) { | ||
// Trigger dashboard refresh by updating a field or simulating a reload | ||
dashboardGR.setValue('last_refreshed', gs.nowDateTime()); | ||
dashboardGR.update(); | ||
gs.info('Dashboard with sys_id ' + dashboardSysId + ' refreshed at ' + gs.nowDateTime()); | ||
} else { | ||
gs.error('Dashboard with sys_id ' + dashboardSysId + ' not found.'); | ||
} | ||
} | ||
|
||
// Call the function to refresh the specified dashboard | ||
refreshDashboard(dashboardSysId); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This field does not exist on W and X instances. Additionally, ServiceNow dashboards load their data on open and can be refreshed through a page. Reports can be run on a schedule for emails