Skip to content

Commit ba72b4a

Browse files
authored
Warn for changed OOTB artifacts (ServiceNowDevProgram#875)
* Create readme.md * Create create_admin_user.js * Create warn_for_changed_ootb_artifacts.js Initial Commit * Create readme.md Initial Commit * Add files via upload * Update readme.md Added screesnhot
1 parent ad92705 commit ba72b4a

File tree

3 files changed

+76
-0
lines changed

3 files changed

+76
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Description
2+
3+
Changing OOTB artifacts like Script Includes or Business Rules is never a good idea, as you will get so called skipped records in the next upgrade/patch you have to care about. Otherwise, you can get into big trouble and risk broken functionalities as well as unpredictable behavior. But many developers are not aware about the consequences when playing around with OOTB artifacts or have no idea about how to revert the changes (see https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0993700 if you don't know how).
4+
5+
Therefore I implemented the Busines Rule "Warn for changed OOTB artifacts" which displays a warning when opening a modified OOTB artifact. The warning message also provides a link to the most recent OOTB version, where you will find a UI Action for reverting to that version.
6+
7+
# Business Rule
8+
9+
The JavaScript code of the Business Rule is written in way that be also used with a scoped application.
10+
11+
**Table:** `sys_metadata`
12+
13+
**When:** display
14+
15+
# Result
16+
17+
![Result](./screenshot.png)
81.8 KB
Loading
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
(function executeRule(current) {
2+
3+
var _strCurrentTable = String(current.getTableName() || '');
4+
var _strCurrentURL = String(gs.action.getGlideURI() || '');
5+
6+
if (_strCurrentTable.length === 0) {
7+
return;
8+
}
9+
10+
//only continue with form views in the Classic UI
11+
if (!_strCurrentURL.startsWith(_strCurrentTable + '.do')) {
12+
return;
13+
}
14+
15+
//determine the unique artifact ID
16+
var _strUpdateName =
17+
String(
18+
current.getValue('sys_update_name') ||
19+
new GlideUpdateManager2().getUpdateName(current) ||
20+
''
21+
);
22+
23+
//Is this artifact tracked with versions?
24+
if (_strUpdateName.length > 0) {
25+
var _grUpdateXml = new GlideRecord('sys_update_xml');
26+
27+
//query all versions
28+
_grUpdateXml.addQuery('name', _strUpdateName);
29+
_grUpdateXml.orderByDesc('sys_updated_on');
30+
_grUpdateXml.setLimit(1);
31+
_grUpdateXml.query();
32+
33+
//was the artifact changed and has a baseline version available?
34+
if (_grUpdateXml.next() && !_grUpdateXml.replace_on_upgrade) {
35+
var _isOOTB = false;
36+
var _grVersion = new GlideRecord('sys_update_version');
37+
38+
_grVersion.addQuery('name', _strUpdateName);
39+
_grVersion.orderByDesc('sys_recorded_at');
40+
_grVersion.query();
41+
42+
//iterate the versions to check whether this is an OOTB artifact
43+
while (!_isOOTB && _grVersion.next()) {
44+
var _strSource = _grVersion.getValue('source_table') || '';
45+
46+
_isOOTB = _strSource === 'sys_upgrade_history' || _strSource === 'sys_store_app';
47+
}
48+
49+
if (_isOOTB) {
50+
gs.addErrorMessage(
51+
'This OOTB artifact was changed and thus will create an skipped record during the next ' +
52+
'upgrade!<br><br>In case the change was done accidentally, you should revert to the <a href="' +
53+
_grVersion.getLink(true) + '" target="_blank">most recent OOTB version.</a>'
54+
);
55+
}
56+
}
57+
}
58+
59+
})(current);

0 commit comments

Comments
 (0)