Vegard S
Mega Sage
Options
- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on 08-17-2021 04:44 AM
I just want to share this code snippet after some digging around.
I had to create a Request form which basically collects data from change templates.
And noticed the template field has "template" as a field type, and those can't be easily queried.
After struggling for a bit, I found a nice script which lets me query the std_change_template table, to find standard change templates. Then I collect the data and store it in an object, which I then can pass to the fields I want.
var grGlide = new GlideRecord("std_change_template");
grGlide.query();
while(grGlide._next()){
var template = grGlide.getValue('template');
var fields =
template
.split('^')
.filter(function(pair){
// Ignore anything that isn't a key/value pair
return pair.indexOf('=') > -1;
})
.map(function(pair){
return pair.split('=');
})
.reduce(function(output, pair){
output[pair[0]] = pair[1];
return output;
}, {});
if (fields.assignment_group == '52cbffacdbfa5c145215582cd39619cf') {
gs.log('Data from the template: ' + fields.short_description);
gs.log(fields);
}
}
Notice the grGlide._next() instead of the regular grGlide.next().
This is because there's a field called .next on the table, so the query just fails.
Labels:
- 1,157 Views
Comments
Edmundo Jimenez
Tera Expert
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
06-06-2023
12:15 PM
It worked perfect, thank you
