Script to create reporting settings on user created Flows, Subflows, and Actions
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago
I was annoyed to find that reporting had been disabled on my Flows and Actions after upgrading to Australia. I was told to update each one individually when required, which seems akin to closing the gate after the horse has bolted. So, I've created a script to set reporting on all user-created Flows, Subflows, and Actions. Use this at your own risk. Read this article to understand the potential impact: https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB3024064
if you have any concerns, comments, suggestions, please respond below. Thanks
// This script creates reporting settings for Flow, Subflows, and Actions
// Toggle the updateFlows and updateActions variables depending on what you'd like to update
// Set a reporting level
// Set logging if required
// This script will not update records created by admin, maint, or anyone at ServiceNow, as per the flowActionGr.addEncodedQuery('sys_created_byNOT LIKE@snc'); encoded query
// Uncomment flowActionGr.setLimit(3); for testing a small number of records
(function() {
var updateFlows = true; // true | false
var updateActions = true; // true | false
var reporting = 'FULL'; // BASIC | FULL | TRACE | OFF
var logging = ''; // WARN | ERROR | INFO | DEBUG
// Validate variables
if (reporting == '') {
gs.info('Set a reporting level');
return;
} else if (reporting != 'BASIC' && reporting != 'FULL' && reporting != 'TRACE' && reporting != 'OFF') {
gs.info('Set a valid option for reporting (BASIC, FULL, TRACE, or OFF)');
return;
}
if (logging != '' && logging != 'WARN' && logging != 'ERROR' && logging != 'INFO' && logging != 'DEBUG') {
gs.info('Set a valid option for logging (WARN, ERROR, INFO, or DEBUG)');
return;
}
if (updateFlows == true) {
createReportSettings('sys_hub_flow', 'flow');
}
if (updateActions == true) {
createReportSettings('sys_hub_action_type_definition', 'action');
}
function createReportSettings(table, flowType) {
var flowActionGr = new GlideRecord(table);
// flowActionGr.setLimit(3); // Limit for testing
flowActionGr.addActiveQuery();
flowActionGr.addQuery('sys_created_by', '!=', 'admin').addCondition('sys_created_by', '!=', 'maint');
flowActionGr.addEncodedQuery('sys_created_byNOT LIKE@snc');
flowActionGr.query();
while (flowActionGr.next()) {
var newReportSettingsGr = new GlideRecord('sys_flow_execution_setting');
if (newReportSettingsGr.get('source', flowActionGr.sys_id)) {
gs.info('Reporting is already set to ' + newReportSettingsGr.reporting + ' for "' + newReportSettingsGr.source.name + '" ' + flowType);
} else {
newReportSettingsGr.initialize();
newReportSettingsGr.setValue('source_type', table);
newReportSettingsGr.setValue('source', flowActionGr.sys_id);
newReportSettingsGr.setValue('reporting', reporting);
newReportSettingsGr.setValue('logging', logging);
newReportSettingsGr.insert();
gs.info('"' + newReportSettingsGr.source.name + '" ' + flowType + ' reporting set to ' + reporting);
}
}
}
})();
0 REPLIES 0