From 7547794603be07d9e5f1e975c6097dba125e43ce Mon Sep 17 00:00:00 2001 From: Soumyadeep Dutta <78016846+Soumyadeep10@users.noreply.github.com> Date: Mon, 13 Oct 2025 17:48:00 +0530 Subject: [PATCH 1/4] Create README.md --- .../README.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 Core ServiceNow APIs/GlideAggregate/Get top 5 CIs with most number of Open Incidents/README.md diff --git a/Core ServiceNow APIs/GlideAggregate/Get top 5 CIs with most number of Open Incidents/README.md b/Core ServiceNow APIs/GlideAggregate/Get top 5 CIs with most number of Open Incidents/README.md new file mode 100644 index 0000000000..c3012906c7 --- /dev/null +++ b/Core ServiceNow APIs/GlideAggregate/Get top 5 CIs with most number of Open Incidents/README.md @@ -0,0 +1,13 @@ +Use-case: +**Fetch Top 5 CIs with the most number of Open Incidents along with the count** + +Type of Script writted: **Background Script** + +**How the code works:** +The code uses the GlideAggregate API to efficiently calculate and retrieve the results - +1. A GlideAggregate query is initiated on the Incident table. The query is restricted to only active Incidents. +2. The query instructs the database to COUNT records grouped by the configuration item(cmdb_ci). +3. Furthermore, the records are instructed to be in descending order of number of incidents related to one CI, also a limit + of 5 records are applied to be fetched. +4. The query is executed and a loop is iterated over these 5 records to fetch and print + the CI name and its corresponding incident count. From 5ed384184e05ab25632d545f4853c757393dedec Mon Sep 17 00:00:00 2001 From: Soumyadeep Dutta <78016846+Soumyadeep10@users.noreply.github.com> Date: Mon, 13 Oct 2025 17:49:25 +0530 Subject: [PATCH 2/4] Create getCIwithmostActiveInc.js --- .../getCIwithmostActiveInc.js | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 Core ServiceNow APIs/GlideAggregate/Get top 5 CIs with most number of Open Incidents/getCIwithmostActiveInc.js diff --git a/Core ServiceNow APIs/GlideAggregate/Get top 5 CIs with most number of Open Incidents/getCIwithmostActiveInc.js b/Core ServiceNow APIs/GlideAggregate/Get top 5 CIs with most number of Open Incidents/getCIwithmostActiveInc.js new file mode 100644 index 0000000000..2abf6fdb8b --- /dev/null +++ b/Core ServiceNow APIs/GlideAggregate/Get top 5 CIs with most number of Open Incidents/getCIwithmostActiveInc.js @@ -0,0 +1,24 @@ +var countOfCI = 5; +var inc = new GlideAggregate('incident'); +inc.addActiveQuery(); +inc.addAggregate('COUNT', 'cmdb_ci'); +inc.groupBy('cmdb_ci'); +inc.orderByAggregate('COUNT', 'cmdb_ci'); +inc.setLimit(countOfCI); +inc.query(); +gs.info('---Top ' + countOfCI + ' CIs with Most Open Incidents---'); + + +while (inc.next()) { + var ciName; + var ciSysID = inc.cmdb_ci; + var count = inc.getAggregate('COUNT', 'cmdb_ci'); + var ci = new GlideRecord('cmdb_ci'); + if (ci.get(ciSysID)) { //retrieving the CI record + ciName = ci.name.toString(); + } else { + ciName = 'Invalid CI'; + } + + gs.info('. CI: ' + ciName + ' | Count of Inc: ' + count); +} From 16278cd81a41ed74eaf37dd279a4d4cf31fdd64b Mon Sep 17 00:00:00 2001 From: Soumyadeep Dutta <78016846+Soumyadeep10@users.noreply.github.com> Date: Wed, 15 Oct 2025 16:11:11 +0530 Subject: [PATCH 3/4] Create README.md --- .../Publish a Retired Knowledge Article again/README.md | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 Client-Side Components/UI Actions/Publish a Retired Knowledge Article again/README.md diff --git a/Client-Side Components/UI Actions/Publish a Retired Knowledge Article again/README.md b/Client-Side Components/UI Actions/Publish a Retired Knowledge Article again/README.md new file mode 100644 index 0000000000..c53505944e --- /dev/null +++ b/Client-Side Components/UI Actions/Publish a Retired Knowledge Article again/README.md @@ -0,0 +1,9 @@ +**UI Action**: +Publish a Retired Knowledge Article again after it is already retired. + +**How it works:** +1. The code finds existing articles in the Knowledge base that share the same Article ID but are not the current article and are 'retired'. +2. It updates the workflow state of these found articles to 'outdated'. +3. For the current article, it sets the workflow_state to 'pubblished', records the current date and updates the 'published' field with the date. +4. It also removes the pre-existing 'retired' date from the 'retired' field. +5. It redirects the user to the updated current record. From 1f10ac42e00bd55f67fda518904c2f5e9233488b Mon Sep 17 00:00:00 2001 From: Soumyadeep Dutta <78016846+Soumyadeep10@users.noreply.github.com> Date: Wed, 15 Oct 2025 16:14:37 +0530 Subject: [PATCH 4/4] Create publishretiredkb.js --- .../publishretiredkb.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 Client-Side Components/UI Actions/Publish a Retired Knowledge Article again/publishretiredkb.js diff --git a/Client-Side Components/UI Actions/Publish a Retired Knowledge Article again/publishretiredkb.js b/Client-Side Components/UI Actions/Publish a Retired Knowledge Article again/publishretiredkb.js new file mode 100644 index 0000000000..81d31b78b7 --- /dev/null +++ b/Client-Side Components/UI Actions/Publish a Retired Knowledge Article again/publishretiredkb.js @@ -0,0 +1,15 @@ +var kbArticle = new GlideRecord('kb_knowledge'); +kbArticle.setWorkflow(false); +kbArticle.addQuery('article_id', current.article_id); +kbArticle.addQuery('sys_id', "!=", current.sys_id); //articles that are not the current one +kbArticle.addQuery('workflow_state', 'retired'); +kbArticle.query(); +while (kbArticle.next()) { + kbArticle.workflow_state = 'outdated'; //setting the articles as outdated + kbArticle.update(); +} +current.workflow_state = 'published'; //publishing retired kb article again +current.published = new GlideDate(); +current.retired = ""; //clearing retired field value +current.update(); +action.setRedirectURL(current);