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 1/8] 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 2/8] 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 3/8] 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 4/8] 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 5/8] 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 6/8] 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 7/8] 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 8/8] 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}`); + } +}