-
Notifications
You must be signed in to change notification settings - Fork 170
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ECMAScript 12 supported code for Syntax Editor Macros #166
Changes from all commits
b13d79c
f3da235
9bd2fc9
15342c8
6cf3219
2774b62
f4c2474
da6546d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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?.()) { | ||
console.log(ga.getAggregate('COUNT') ?? 0); | ||
} |
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?.()) { | ||
console.log(`Incident ${gr.number} was updated within the last 30 days.`); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a code snippet, not a macro |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}`); | ||
} | ||
} |
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 | ||
} |
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?.(); |
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'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
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?.(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
console.log
does not resolve server-side