-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
1 parent
2d7b1ca
commit b50896b
Showing
5 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// Insert a new record | ||
let gr = new GlideRecord('table_name'); | ||
gr.initialize(); | ||
gr.field_name = 'value'; | ||
gr.insert?.(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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?.(); | ||
} | ||
} |