Dashboards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2024 12:25 AM
I want delete multiple dashboards using Scripting.
Any idea help me.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2024 12:33 AM
Hello @ServiceNow40 ,
Here is the sample script for your use case:
var grDashboard = new GlideRecord('pa_dashboard');
grDashboard.addQuery('name', 'STARTSWITH', 'Test');
grDashboard.query();
var count = 0;
while (grDashboard.next()) {
gs.print('Deleting dashboard: ' + grDashboard.name + ' [sys_id: ' + grDashboard.sys_id + ']');
grDashboard.deleteRecord();
count++;
}
gs.info('Total dashboards deleted: ' + count);
If you find my response helpful, please consider marking it as the 'Accepted Solution' and giving it a 'Helpful' rating. Your feedback not only supports the community but also encourages me to continue providing valuable assistance.
Thanks,
Amitoj Wadhera
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2024 12:37 AM
so what script did you start with and where are you stuck?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2024 12:40 AM
Hi Ankur,
I know how to delete the dashboards without script.
But i need to delete multiple dashboards using script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2024 01:46 AM
You can delete multiple dashboards using a script by querying the sys_portal table, which stores dashboard records, and then using a GlideRecord loop to delete the desired dashboards.
var gr = new GlideRecord('sys_portal');
gr.addQuery('name', 'CONDITIOn');
gr.query();
while (gr.next()) {
gr.deleteRecord();
}