How to unpublish a report using script?

HarI98
Tera Expert

Hello community,

How to unpublish a report using script?
I tried switching the is_published to True but if I go to the report then and check if it was published, it wont be.
So it has to be something else that I'm not aware of.

Would appreciate pointers/tips.

Thanks in advance!

1 ACCEPTED SOLUTION

Hi, I ended up raising a HI Case to ask SN about this and this is what they responded. (basically cant do it with script)

find_real_file.png

View solution in original post

15 REPLIES 15

Hi,

for bulk update you can use script

var gr = new GlideRecord('sys_report');
gr.addQuery('name', 'IN' ,'report1,report2'); // give report names as comma separated
gr.query();
while(gr.next()){
gr.is_published = false;
gr.setWorkflow(false);
gr.update();
}

Regards
Ankur

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

As I replied into Mohids chain, is this issue on the Sharing tab happening because I did not disable the workflow?

Also had to disable the OOTB business rule "Report roles updated - is_publish field" to even be able to change it by script

Hi,

As mentioned in my script you should be using setWorkflow(false) to avoid triggering any BR

Don't disable OOB BR

Regards
Ankur

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

Thanks Ankur,

One last question.

Even though it updates it on the report form and I can see in the XML is_published is set on false, when I go to view the report and open the sharing tab it still says "Unpublish" like it's still published.

Why is that? Which one reflects the actual state of the report? If users decide they want this report they might be confused when getting an email about a report that was unpublished, but on the Sharing tab it looks like published still.

find_real_file.png

Hi Harl,

In that case you should use the manual way I guess so that it should not show 'unpublish' option for unpublished reports.

 

Thanks,

Mohit Kaushik

Thanks,
Mohit Kaushik
ServiceNow MVP (2023-2025)