diff --git a/Client-Side Components/UI Pages/Share reports with users and groups/Image 1.png b/Client-Side Components/UI Pages/Share reports with users and groups/Image 1.png new file mode 100644 index 0000000000..15888fba6e Binary files /dev/null and b/Client-Side Components/UI Pages/Share reports with users and groups/Image 1.png differ diff --git a/Client-Side Components/UI Pages/Share reports with users and groups/Image 2.png b/Client-Side Components/UI Pages/Share reports with users and groups/Image 2.png new file mode 100644 index 0000000000..a6b6cd8cc7 Binary files /dev/null and b/Client-Side Components/UI Pages/Share reports with users and groups/Image 2.png differ diff --git a/Client-Side Components/UI Pages/Share reports with users and groups/Image 3.png b/Client-Side Components/UI Pages/Share reports with users and groups/Image 3.png new file mode 100644 index 0000000000..51fdf9fe87 Binary files /dev/null and b/Client-Side Components/UI Pages/Share reports with users and groups/Image 3.png differ diff --git a/Client-Side Components/UI Pages/Share reports with users and groups/README.md b/Client-Side Components/UI Pages/Share reports with users and groups/README.md new file mode 100644 index 0000000000..292446c626 --- /dev/null +++ b/Client-Side Components/UI Pages/Share reports with users and groups/README.md @@ -0,0 +1,17 @@ +**Usecase:** +Currenlty there's no OOB feature to share the all the reports from the particular dashboard with the user or group at a time. Also, sharing the dashboard with the user/group doesnot share the corresponding reports with them automatically. +In order to do that, admin or report owner should open each report and share them individually. +If the dashboard has more reports i.e 20+, then it'll take a considerable amount of time to complete this task. +To reduce the manual effort, we can use this custom logic to share all the reports from the particular dashboard at a time. + +**Pre-requisite:** +A database view which shows the reports shared with atleast one dashboard need to be created. +ServiceNow community article link which explains how to build one..(Thanks to Adam Stout for this) +https://www.servicenow.com/community/performance-analytics-blog/view-reports-on-a-dashboard-and-dashboards-using-a-report/ba-p/2271548 + +**Components:** +1. UI Page: It contains Jelly script (HTML), Client script and Processing script. Used to capture the user/group info and share the rports with them. +2. UI Action(Client): Created on the Dashboards (pa_dashboards) table. Used to open the UI page as apopup/modal window + +This UI action is visible on the dashboard properties page (image attached) + diff --git a/Client-Side Components/UI Pages/Share reports with users and groups/UI Page/ui_page.html b/Client-Side Components/UI Pages/Share reports with users and groups/UI Page/ui_page.html new file mode 100644 index 0000000000..76a79dd3e6 --- /dev/null +++ b/Client-Side Components/UI Pages/Share reports with users and groups/UI Page/ui_page.html @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + diff --git a/Client-Side Components/UI Pages/Share reports with users and groups/UI Page/ui_page_client_script.js b/Client-Side Components/UI Pages/Share reports with users and groups/UI Page/ui_page_client_script.js new file mode 100644 index 0000000000..b31e2608c0 --- /dev/null +++ b/Client-Side Components/UI Pages/Share reports with users and groups/UI Page/ui_page_client_script.js @@ -0,0 +1,10 @@ +function onCancel() { + var c = gel('cancelled'); + c.value = "true"; + GlideModal.get().destroy(); + return false; +} + +function onSubmit() { + return true; +} diff --git a/Client-Side Components/UI Pages/Share reports with users and groups/UI Page/ui_page_processing_script.js b/Client-Side Components/UI Pages/Share reports with users and groups/UI Page/ui_page_processing_script.js new file mode 100644 index 0000000000..aaae977e80 --- /dev/null +++ b/Client-Side Components/UI Pages/Share reports with users and groups/UI Page/ui_page_processing_script.js @@ -0,0 +1,71 @@ +if (cancelled == "false") { + var dashboard_id = key; // sys id of the dashboard from the Jelly script + var group_id = group; // sys id of group from the Jelly script + var user_id = user; //sys id of user from the Jelly script + + if (!gs.nil(group_id) || !gs.nil(user_id)) { + groupShare(dashboard_id, group_id); + userShare(dashboard_id, user_id); + response.sendRedirect("pa_dashboards.do?sys_id=" + key); + } else { + response.sendRedirect("pa_dashboards.do?sys_id=" + key); + gs.addErrorMessage("Please select group/user"); + } +} else { + response.sendRedirect("pa_dashboards.do?sys_id=" + key); +} + +function groupShare(dashboard_id, group_id) { + var db_view = new GlideRecord('u_reports_shared_with_dashboard'); // Database view name + db_view.addEncodedQuery('repstat_report_sys_id!=^dt_dashboard=' + dashboard_id); + db_view.query(); + while (db_view.next()) { + var report_id = db_view.rep_sys_id; + + var rec = new GlideRecord("sys_report"); + rec.get(report_id); + rec.user = "group"; + rec.update(); + + var report_sharing = new GlideRecord('sys_report_users_groups'); + report_sharing.addQuery('group_id', group_id); + + report_sharing.addQuery('report_id', report_id); + report_sharing.query(); + if (!report_sharing.next()) { + var new_record = new GlideRecord('sys_report_users_groups'); + new_record.initialize(); + new_record.report_id = report_id; + new_record.group_id = group_id; + new_record.insert(); + } + + } +} + +function userShare(dashboard_id, user_id) { + var db_view = new GlideRecord('u_reports_shared_with_dashboard'); + db_view.addEncodedQuery('repstat_report_sys_id!=^dt_dashboard=' + dashboard_id); + db_view.query(); + while (db_view.next()) { + var report_id = db_view.rep_sys_id; + + var rec = new GlideRecord("sys_report"); + rec.get(report_id); + rec.user = "group"; + rec.update(); + + var report_sharing = new GlideRecord('sys_report_users_groups'); + report_sharing.addQuery('user_id', user_id); + report_sharing.addQuery('report_id', report_id); + report_sharing.query(); + if (!report_sharing.next()) { + var new_record = new GlideRecord('sys_report_users_groups'); + new_record.initialize(); + new_record.report_id = report_id; + new_record.user_id = user_id; + new_record.insert(); + } + + } +} diff --git a/Client-Side Components/UI Pages/Share reports with users and groups/ui_action_script.js b/Client-Side Components/UI Pages/Share reports with users and groups/ui_action_script.js new file mode 100644 index 0000000000..5e5c09aa85 --- /dev/null +++ b/Client-Side Components/UI Pages/Share reports with users and groups/ui_action_script.js @@ -0,0 +1,23 @@ +/* +UI Action details: + +Active: True +Name: Share reports +Table: Dashboard [pa_dashboards] +Order: 1000 +Action name: share_report +Show update: True +Client: True +List v2 Compatible: True +Form button: True +Form style: Primary +Onclick: shareReport(); + +*/ + +function shareReport() { + var modal = new GlideModal("sj_share_reports"); // UI Page id + modal.setTitle("Share Reports"); + modal.setPreference('sysparm_key', g_form.getUniqueValue()); + modal.render(); +}