Skip to content

Commit b50896b

Browse files
ECMAScript 12 supported code for Syntax Editor Macros (#168)
* Create letgr ES12 Supported syntax * Rename letgr to GetRecordsES12 * Create InsertRecordES12 * Create GlideAggregateES12 * Create UpdateRelatedRecords * Create UpdatedWithinList * Rename UpdatedWithinList to UpdatedWithinList.js * Create CIsToTasksRelation * Update GlideAggregateES12 Updated console.log to gs.info * Update UpdatedWithinList.js Replaced console.log with gs.info * Delete GlideRecord/CIsToTasksRelation Deleted code snippet * Update UpdateRelatedRecords Removed $ as it applies to only integer
1 parent 2d7b1ca commit b50896b

File tree

5 files changed

+47
-0
lines changed

5 files changed

+47
-0
lines changed

GlideAggregate/GlideAggregateES12

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Count records in a table that match a specific condition
2+
let ga = new GlideAggregate('table_name');
3+
ga.addAggregate('COUNT');
4+
ga.addQuery('field', 'value');
5+
ga.query();
6+
7+
if (ga.next?.()) {
8+
gs.info(ga.getAggregate('COUNT') ?? 0);
9+
}

GlideDateTime/UpdatedWithinList.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Retrieve records updated within the last 30 days using date filtering
2+
let gr = new GlideRecord('incident');
3+
let date = new GlideDateTime();
4+
date.subtract(30 * 24 * 60 * 60 * 1000); // 30 days ago
5+
gr.addQuery('sys_updated_on', '>=', date);
6+
gr.query();
7+
8+
while (gr.next?.()) {
9+
gs.info('Incident ${gr.number} was updated within the last 30 days.');
10+
}

GlideRecord/GetRecordsES12

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Code for fethcing the records via GlideRecord supporting ES12 syntax
2+
let gr = new GlideRecord("$0");
3+
gr.addQuery("name", "value");
4+
gr.query();
5+
6+
if (gr.next?.()) {
7+
// Do something if the record exists
8+
}

GlideRecord/InsertRecordES12

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Insert a new record
2+
let gr = new GlideRecord('table_name');
3+
gr.initialize();
4+
gr.field_name = 'value';
5+
gr.insert?.();

GlideRecord/UpdateRelatedRecords

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Retrieve related records from another table and process them
2+
let parentGR = new GlideRecord('parent_table');
3+
parentGR.addEncodedQuery('query');
4+
parentGR.query();
5+
6+
while (parentGR.next?.()) {
7+
let taskGR = new GlideRecord('child_table');
8+
taskGR.addQuery('parent', parentGR.sys_id);
9+
taskGR.query();
10+
11+
while (taskGR.next?.()) {
12+
taskGR.state = 'value';
13+
taskGR.update?.();
14+
}
15+
}

0 commit comments

Comments
 (0)