- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2025 01:00 PM
Hello,
I am trying to create a business rule that would get the opened_at from the change_request table
And carry it over to the appropriate standard change template and populate the opened_at date into the u_last_used date one the template form on the std_change_record_producer table.
This would change every time that template is submitted. The purpose is to be able to run a report and see when the last time a template was used.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2025 01:31 PM
Hello @Darlene York ,
The following Business Rule will achieve this:
Note: the Filter Condition is "Standard Change Template version" => "Template" | "is not empty".
Script:
(function executeRule(current, previous /*null when async*/) {
var template = current.std_change_producer_version.std_change_producer.getRefRecord();
template.u_last_used = gs.nowDateTime();
template.update();
})(current, previous);
Regards,
Robert
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2025 11:18 PM - edited 04-18-2025 11:46 PM
Hello @Darlene York ,
Sure, please use the following Fix Script to update all Standard Change Templates based on the most recently created Change Request for each:
var gaChg = new GlideAggregate('change_request'),
templateField = 'std_change_producer_version.std_change_producer';
gaChg.addNotNullQuery(templateField);
gaChg.groupBy(templateField);
gaChg.addAggregate('MAX', 'sys_created_on');
gaChg.query();
while (gaChg.next()) {
new GlideQuery('std_change_record_producer')
.where('sys_id', gaChg.getValue(templateField))
.update({
u_last_used: gaChg.getAggregate('MAX', 'sys_created_on')
});
}
Regards,
Robert
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2025 01:31 PM
Hello @Darlene York ,
The following Business Rule will achieve this:
Note: the Filter Condition is "Standard Change Template version" => "Template" | "is not empty".
Script:
(function executeRule(current, previous /*null when async*/) {
var template = current.std_change_producer_version.std_change_producer.getRefRecord();
template.u_last_used = gs.nowDateTime();
template.update();
})(current, previous);
Regards,
Robert
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2025 01:55 PM
Hi Robert,
Thank you so much that worked perfectly!
Have a great weekend!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2025 02:08 PM
Robert,
One more thing do you know if there is a way to make this retroactive so hi will update the last used date on all the standard templates? It works great if I submit a new standard change. It updates it just the way I want it too.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2025 11:18 PM - edited 04-18-2025 11:46 PM
Hello @Darlene York ,
Sure, please use the following Fix Script to update all Standard Change Templates based on the most recently created Change Request for each:
var gaChg = new GlideAggregate('change_request'),
templateField = 'std_change_producer_version.std_change_producer';
gaChg.addNotNullQuery(templateField);
gaChg.groupBy(templateField);
gaChg.addAggregate('MAX', 'sys_created_on');
gaChg.query();
while (gaChg.next()) {
new GlideQuery('std_change_record_producer')
.where('sys_id', gaChg.getValue(templateField))
.update({
u_last_used: gaChg.getAggregate('MAX', 'sys_created_on')
});
}
Regards,
Robert