- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-16-2020 04:37 AM
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!
Solved! Go to Solution.
- Labels:
-
Reporting
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-17-2020 05:18 AM
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)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-16-2020 04:51 AM
Hi Harl,
You can write a script Background, scheduled job (if its frequent with certain conditions), fix script etc to achieve this.
Before that you need to see if you have access to that report or not. I guess admin should be able to update all the reports.
Script can be something like this.
var rep = new GlideRecord('sys_report');
rep.addQuery('sys_id','sys id of the report you want to unpublish');
rep.query();
if(rep.next())
{
rep.is_published = false;//This should unpublish the report.
}
Please mark this answer as correct and helpful if it resolves the query and helpful alone if it lead you in right direction.
Thanks,
Mohit Kaushik
Mohit Kaushik
ServiceNow MVP (2023-2025)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-16-2020 05:07 AM
Hi Mohit,
The query I ran to test this in the background script was
var rep = new GlideRecord('sys_report');
rep.get('822c14c1c38102002ba7e219cdba8ffe');
rep.is_published = false;
rep.update();
Even though it updates it on the report form and I can see in the XML it 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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-16-2020 05:25 AM
Hey Harl,
Please add the below line as well to the script
rep.setWorkflow(false);
before update.
As I ran the query and saw there was another BR(Report roles updated - is_publish field) which was not letting the the version to get updated and making a copy of it.
So disabling other rules will let your script work.
Thanks,
Mohit Kaushik
Mohit Kaushik
ServiceNow MVP (2023-2025)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-16-2020 04:57 AM