From b13d79c919e7c671d2461dd9778d8de88bbce037 Mon Sep 17 00:00:00 2001 From: Deepak Negi <120473057+dvn-lazywinner@users.noreply.github.com> Date: Sat, 26 Oct 2024 23:05:01 +0530 Subject: [PATCH 01/12] Create letgr ES12 Supported syntax --- GlideRecord/letgr | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 GlideRecord/letgr diff --git a/GlideRecord/letgr b/GlideRecord/letgr new file mode 100644 index 0000000..23fa504 --- /dev/null +++ b/GlideRecord/letgr @@ -0,0 +1,8 @@ +// Code for fethcing the records via GlideRecord supporting ES12 syntax +let gr = new GlideRecord("$0"); +gr.addQuery("name", "value"); +gr.query(); + +if (gr.next?.()) { + // Do something if the record exists +} From f3da2356d080fe246978162c27d89a29aef16105 Mon Sep 17 00:00:00 2001 From: Deepak Negi <120473057+dvn-lazywinner@users.noreply.github.com> Date: Sat, 26 Oct 2024 23:05:48 +0530 Subject: [PATCH 02/12] Rename letgr to GetRecordsES12 --- GlideRecord/{letgr => GetRecordsES12} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename GlideRecord/{letgr => GetRecordsES12} (100%) diff --git a/GlideRecord/letgr b/GlideRecord/GetRecordsES12 similarity index 100% rename from GlideRecord/letgr rename to GlideRecord/GetRecordsES12 From 9bd2fc91fabd51b8584f700387001288eeba2d80 Mon Sep 17 00:00:00 2001 From: Deepak Negi <120473057+dvn-lazywinner@users.noreply.github.com> Date: Sat, 26 Oct 2024 23:09:45 +0530 Subject: [PATCH 03/12] Create InsertRecordES12 --- GlideRecord/InsertRecordES12 | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 GlideRecord/InsertRecordES12 diff --git a/GlideRecord/InsertRecordES12 b/GlideRecord/InsertRecordES12 new file mode 100644 index 0000000..b02e226 --- /dev/null +++ b/GlideRecord/InsertRecordES12 @@ -0,0 +1,5 @@ +// Insert a new record +let gr = new GlideRecord('table_name'); +gr.initialize(); +gr.field_name = 'value'; +gr.insert?.(); From 15342c8ce7dc10e1c8cd1ac471261452f052a4dd Mon Sep 17 00:00:00 2001 From: Deepak Negi <120473057+dvn-lazywinner@users.noreply.github.com> Date: Sat, 26 Oct 2024 23:12:02 +0530 Subject: [PATCH 04/12] Create GlideAggregateES12 --- GlideAggregate/GlideAggregateES12 | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 GlideAggregate/GlideAggregateES12 diff --git a/GlideAggregate/GlideAggregateES12 b/GlideAggregate/GlideAggregateES12 new file mode 100644 index 0000000..069fec3 --- /dev/null +++ b/GlideAggregate/GlideAggregateES12 @@ -0,0 +1,9 @@ +// Count records in a table that match a specific condition +let ga = new GlideAggregate('table_name'); +ga.addAggregate('COUNT'); +ga.addQuery('field', 'value'); +ga.query(); + +if (ga.next?.()) { + console.log(ga.getAggregate('COUNT') ?? 0); +} From 6cf321955369f79059f666dae9e4cf6de2bff413 Mon Sep 17 00:00:00 2001 From: Deepak Negi <120473057+dvn-lazywinner@users.noreply.github.com> Date: Sat, 26 Oct 2024 23:14:47 +0530 Subject: [PATCH 05/12] Create UpdateRelatedRecords --- GlideRecord/UpdateRelatedRecords | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 GlideRecord/UpdateRelatedRecords diff --git a/GlideRecord/UpdateRelatedRecords b/GlideRecord/UpdateRelatedRecords new file mode 100644 index 0000000..7a08772 --- /dev/null +++ b/GlideRecord/UpdateRelatedRecords @@ -0,0 +1,15 @@ +// Retrieve related records from another table and process them +let parentGR = new GlideRecord('$parent_table'); +parentGR.addEncodedQuery('$query'); +parentGR.query(); + +while (parentGR.next?.()) { + let taskGR = new GlideRecord('$child_table'); + taskGR.addQuery('parent', parentGR.sys_id); + taskGR.query(); + + while (taskGR.next?.()) { + taskGR.state = '$value'; + taskGR.update?.(); + } +} From 2774b62b14e1865d4ee34a0d1607170853130079 Mon Sep 17 00:00:00 2001 From: Deepak Negi <120473057+dvn-lazywinner@users.noreply.github.com> Date: Sat, 26 Oct 2024 23:18:10 +0530 Subject: [PATCH 06/12] Create UpdatedWithinList --- GlideDateTime/UpdatedWithinList | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 GlideDateTime/UpdatedWithinList diff --git a/GlideDateTime/UpdatedWithinList b/GlideDateTime/UpdatedWithinList new file mode 100644 index 0000000..1dee575 --- /dev/null +++ b/GlideDateTime/UpdatedWithinList @@ -0,0 +1,10 @@ +// Retrieve records updated within the last 30 days using date filtering +let gr = new GlideRecord('incident'); +let date = new GlideDateTime(); +date.subtract(30 * 24 * 60 * 60 * 1000); // 30 days ago +gr.addQuery('sys_updated_on', '>=', date); +gr.query(); + +while (gr.next?.()) { + console.log(`Incident ${gr.number} was updated within the last 30 days.`); +} From f4c2474f152e4b2a2744c9633fa69377230a6249 Mon Sep 17 00:00:00 2001 From: Deepak Negi <120473057+dvn-lazywinner@users.noreply.github.com> Date: Sat, 26 Oct 2024 23:18:30 +0530 Subject: [PATCH 07/12] Rename UpdatedWithinList to UpdatedWithinList.js --- GlideDateTime/{UpdatedWithinList => UpdatedWithinList.js} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename GlideDateTime/{UpdatedWithinList => UpdatedWithinList.js} (100%) diff --git a/GlideDateTime/UpdatedWithinList b/GlideDateTime/UpdatedWithinList.js similarity index 100% rename from GlideDateTime/UpdatedWithinList rename to GlideDateTime/UpdatedWithinList.js From da6546de57f6256bfb91645f3408a0df1aa72472 Mon Sep 17 00:00:00 2001 From: Deepak Negi <120473057+dvn-lazywinner@users.noreply.github.com> Date: Sat, 26 Oct 2024 23:20:31 +0530 Subject: [PATCH 08/12] Create CIsToTasksRelation --- GlideRecord/CIsToTasksRelation | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 GlideRecord/CIsToTasksRelation diff --git a/GlideRecord/CIsToTasksRelation b/GlideRecord/CIsToTasksRelation new file mode 100644 index 0000000..4497f89 --- /dev/null +++ b/GlideRecord/CIsToTasksRelation @@ -0,0 +1,24 @@ +// Query multiple tables to find incidents and changes related to the same CI +let ciGR = new GlideRecord('cmdb_ci'); +ciGR.addQuery('name', 'specific_ci_name'); +ciGR.query(); + +while (ciGR.next?.()) { + // Retrieve related incidents + let incidentGR = new GlideRecord('incident'); + incidentGR.addQuery('cmdb_ci', ciGR.sys_id); + incidentGR.query(); + + while (incidentGR.next?.()) { + console.log(`Incident ${incidentGR.number} related to CI ${ciGR.name}`); + } + + // Retrieve related change requests + let changeGR = new GlideRecord('change_request'); + changeGR.addQuery('cmdb_ci', ciGR.sys_id); + changeGR.query(); + + while (changeGR.next?.()) { + console.log(`Change Request ${changeGR.number} related to CI ${ciGR.name}`); + } +} From 96c7d3ab0cf49a94c58fdfc1ce1c5e2881c2df31 Mon Sep 17 00:00:00 2001 From: Deepak Negi <120473057+dvn-lazywinner@users.noreply.github.com> Date: Wed, 30 Oct 2024 23:33:57 +0530 Subject: [PATCH 09/12] Update GlideAggregateES12 Updated console.log to gs.info --- GlideAggregate/GlideAggregateES12 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GlideAggregate/GlideAggregateES12 b/GlideAggregate/GlideAggregateES12 index 069fec3..81915f1 100644 --- a/GlideAggregate/GlideAggregateES12 +++ b/GlideAggregate/GlideAggregateES12 @@ -5,5 +5,5 @@ ga.addQuery('field', 'value'); ga.query(); if (ga.next?.()) { - console.log(ga.getAggregate('COUNT') ?? 0); + gs.info(ga.getAggregate('COUNT') ?? 0); } From 6ab0fbc2a6fddcb9feaf5438c3b92a6fed8bc92b Mon Sep 17 00:00:00 2001 From: Deepak Negi <120473057+dvn-lazywinner@users.noreply.github.com> Date: Wed, 30 Oct 2024 23:34:52 +0530 Subject: [PATCH 10/12] Update UpdatedWithinList.js Replaced console.log with gs.info --- GlideDateTime/UpdatedWithinList.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GlideDateTime/UpdatedWithinList.js b/GlideDateTime/UpdatedWithinList.js index 1dee575..174d9b2 100644 --- a/GlideDateTime/UpdatedWithinList.js +++ b/GlideDateTime/UpdatedWithinList.js @@ -6,5 +6,5 @@ gr.addQuery('sys_updated_on', '>=', date); gr.query(); while (gr.next?.()) { - console.log(`Incident ${gr.number} was updated within the last 30 days.`); + gs.info('Incident ${gr.number} was updated within the last 30 days.'); } From 7d432e480646dd08a6a2356da7c96a029e9c6996 Mon Sep 17 00:00:00 2001 From: Deepak Negi <120473057+dvn-lazywinner@users.noreply.github.com> Date: Wed, 30 Oct 2024 23:35:34 +0530 Subject: [PATCH 11/12] Delete GlideRecord/CIsToTasksRelation Deleted code snippet --- GlideRecord/CIsToTasksRelation | 24 ------------------------ 1 file changed, 24 deletions(-) delete mode 100644 GlideRecord/CIsToTasksRelation diff --git a/GlideRecord/CIsToTasksRelation b/GlideRecord/CIsToTasksRelation deleted file mode 100644 index 4497f89..0000000 --- a/GlideRecord/CIsToTasksRelation +++ /dev/null @@ -1,24 +0,0 @@ -// Query multiple tables to find incidents and changes related to the same CI -let ciGR = new GlideRecord('cmdb_ci'); -ciGR.addQuery('name', 'specific_ci_name'); -ciGR.query(); - -while (ciGR.next?.()) { - // Retrieve related incidents - let incidentGR = new GlideRecord('incident'); - incidentGR.addQuery('cmdb_ci', ciGR.sys_id); - incidentGR.query(); - - while (incidentGR.next?.()) { - console.log(`Incident ${incidentGR.number} related to CI ${ciGR.name}`); - } - - // Retrieve related change requests - let changeGR = new GlideRecord('change_request'); - changeGR.addQuery('cmdb_ci', ciGR.sys_id); - changeGR.query(); - - while (changeGR.next?.()) { - console.log(`Change Request ${changeGR.number} related to CI ${ciGR.name}`); - } -} From a78737362fee35d09620a3d6be575ba29b7a9d56 Mon Sep 17 00:00:00 2001 From: Deepak Negi <120473057+dvn-lazywinner@users.noreply.github.com> Date: Wed, 30 Oct 2024 23:36:43 +0530 Subject: [PATCH 12/12] Update UpdateRelatedRecords Removed $ as it applies to only integer --- GlideRecord/UpdateRelatedRecords | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/GlideRecord/UpdateRelatedRecords b/GlideRecord/UpdateRelatedRecords index 7a08772..6d7f15a 100644 --- a/GlideRecord/UpdateRelatedRecords +++ b/GlideRecord/UpdateRelatedRecords @@ -1,15 +1,15 @@ // Retrieve related records from another table and process them -let parentGR = new GlideRecord('$parent_table'); -parentGR.addEncodedQuery('$query'); +let parentGR = new GlideRecord('parent_table'); +parentGR.addEncodedQuery('query'); parentGR.query(); while (parentGR.next?.()) { - let taskGR = new GlideRecord('$child_table'); + let taskGR = new GlideRecord('child_table'); taskGR.addQuery('parent', parentGR.sys_id); taskGR.query(); while (taskGR.next?.()) { - taskGR.state = '$value'; + taskGR.state = 'value'; taskGR.update?.(); } }