A very helpful related list in a application record in ServiceNow is the Customized Files related list. I like to take a look at this before uploading my version to the app respository to see what I (and my colleagues) have changed from the OOB app. Grouping by the Class column would be very nice, however, because this is a related list, it doesn’t allow the Group By functionality. To get this, we have to go to sys_metadata table where we run into another problem — there is no column which indicates that this is a customized file. So how does the related list in application record filter for customized file? The answer lies in the Relationship record — it uses sn_app_customization.AppCustomizationAPI.getAppCustomizationFiles(). I think this is a class in Java because I don’t see it anywhere in Script Includes.
If we provide the sys_id of an application record to sn_app_customization.AppCustomizationAPI.getAppCustomizationFiles(), it will return an array of sys_update_name (application file names) of files that are customized in the application. We can use this in a scripted filter to get the sys_id’s of the sys_metadata records and thus pull them up directly in the sys_metadata table. This will allow us to use the Group By functionality on the Class column.
Here’s the script include (create in Global accessible to all scopes, client callable):
function getCustomizedFileSysIds(applicationSysId) {
//if no applicationSysId is specified, use the current scope
if (!applicationSysId) {
applicationSysId = gs.getCurrentApplicationId();
}
var sysIds = [];
var list = new GlideRecord("sys_metadata");
list.addQuery('sys_update_name', 'IN', sn_app_customization.AppCustomizationAPI.getAppCustomizationFiles(applicationSysId));
list.query();
while (list.next()) {
//put all the sys_id's into an array
sysIds.push(list.getUniqueValue());
}
return sysIds;
}
Now head over to the sys_metadata table, switch to whatever scope you’d like to see the customized files for and use the scripted filter:
javascript:getCustomizedFileSysIds()
Run the query and then you can use the group by. Note that if there are thousands of files, your group by may time out.