diff --git a/GlideAggregate/GlideAggregateES12 b/GlideAggregate/GlideAggregateES12 new file mode 100644 index 0000000..81915f1 --- /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?.()) { + gs.info(ga.getAggregate('COUNT') ?? 0); +} diff --git a/GlideDateTime/UpdatedWithinList.js b/GlideDateTime/UpdatedWithinList.js new file mode 100644 index 0000000..174d9b2 --- /dev/null +++ b/GlideDateTime/UpdatedWithinList.js @@ -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?.()) { + gs.info('Incident ${gr.number} was updated within the last 30 days.'); +} diff --git a/GlideRecord/GetRecordsES12 b/GlideRecord/GetRecordsES12 new file mode 100644 index 0000000..23fa504 --- /dev/null +++ b/GlideRecord/GetRecordsES12 @@ -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 +} 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?.(); diff --git a/GlideRecord/UpdateRelatedRecords b/GlideRecord/UpdateRelatedRecords new file mode 100644 index 0000000..6d7f15a --- /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?.(); + } +}