Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Dashboards

ServiceNow40
Tera Contributor

I want delete multiple dashboards using Scripting.

 

Any idea help me.

5 REPLIES 5

Amitoj Wadhera
Kilo Sage

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

Ankur Bawiskar
Tera Patron

@ServiceNow40 

so what script did you start with and where are you stuck?

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

Hi Ankur,

 

I know how to delete the dashboards without script.

 

But i need to delete multiple dashboards using script.

yuvarajkate
Giga Guru

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();
}