Skip to content

Commit 9e06654

Browse files
authored
trying a multi-line string literal for the eric script thing (#452)
1 parent cd8a27f commit 9e06654

File tree

1 file changed

+71
-3
lines changed

1 file changed

+71
-3
lines changed

Parsers/App Update Script.js

Lines changed: 71 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,78 @@ regex:^!newline\b
44
flags:gmi
55
*/
66

7+
const eric_script = `
8+
/*----------------------------------------------------*/
9+
/* */
10+
/* Have a bunch of apps that need to be updated? */
11+
/* Run this and follow the directions in the output */
12+
/* It will build a payload and use the CI/CD API to */
13+
/* run a batch install of all of the needed updates. */
14+
/* */
15+
/*----------------------------------------------------*/
716
8-
var long_script = "/*----------------------------------------------------*/\n/* */\n/* Have a bunch of apps that need to be updated? */\n/* Run this and follow the directions in the output */\n/* It will build a payload and use the CI/CD API to */\n/* run a batch install of all of the needed updates. */\n/* */\n/*----------------------------------------------------*/\n\n//Want Demo Data with the app?\nvar loadDemoData = true;\nvar updateCheck = false; //this can take some time to run and adds a LOT of stuff to the lod making the important bit harder to find\n\nif (updateCheck)\n new sn_appclient.UpdateChecker().checkAvailableUpdates();\n\nvar prevName;\nvar appsArray = [];\nvar grSSA = new GlideRecord('sys_store_app');\ngrSSA.addEncodedQuery('install_dateISNOTEMPTY^hide_on_ui=false^vendor=ServiceNow^ORvendorISEMPTY');\ngrSSA.orderBy('name');\ngrSSA.orderBy('version');\ngrSSA.query();\nwhile (grSSA.next()) {\n var curName = grSSA.getValue('name');\n var latestVersion = updateAvailable(grSSA);\n if (curName == prevName) {\n continue;\n }\n if (latestVersion) {\n prevName = curName;\n var appObject = {\n displayName: curName,\n id: grSSA.getUniqueValue(),\n load_demo_data: loadDemoData,\n type: \"application\",\n requested_version: grSSA.getValue('latest_version')\n };\n appsArray.push(appObject);\n }\n}\nfunction updateAvailable(grSSA) {\n var installedVersion = grSSA.getValue('version');\n var latestVersion = grSSA.getValue('latest_version');\n var installedArray = installedVersion.split('.');\n var latestArray = latestVersion.split('.');\n var len = Math.max(installedArray.length, latestArray.length);\n for (var i = 0; i < len; i++) {\n var installed = installedArray[i] ? parseInt(installedArray[i]) : 0;\n var latest = latestArray[i] ? parseInt(latestArray[i]) : 0;\n if (installed < latest) {\n return true;\n } else if (installed > latest) {\n return false;\n }\n }\n return false;\n}\nif (appsArray.length > 0) {\n var appsPackages = {};\n appsPackages.packages = appsArray;\n appsPackages.name = 'Update Apps';\n var data = new global.JSON().encode(appsPackages);\n\n var url = gs.getProperty('glide.servlet.uri') +'$restapi.do?ns=sn_cicd&service=CICD%20Batch%20Install%20API&version=latest';\n gs.info('\\nOpen the following URL in a new tab:\\n\\n' + url + '\\n\\ncopy/paste the following JSON into the \"Raw\" Request body\\n\\n' + data);\n} else {\n gs.info(\"\\nNo apps to update found.\\nIf you think this is incorrect please try running this script again with `updateCheck` set to `true`. This will check the store for any new updates.\\n\\n(sometimes there are apps in the Application Manager that say that there are updates but you can't actually update them)\");\n}"
17+
//Want Demo Data with the app?
18+
var loadDemoData = true;
19+
var updateCheck = false; //this can take some time to run and adds a LOT of stuff to the lod making the important bit harder to find
920
21+
if (updateCheck)
22+
new sn_appclient.UpdateChecker().checkAvailableUpdates();
1023
11-
var message = "<@U6E2TEKQ9> made a cool script for bulk updating apps!\n\n" + long_script;
24+
var prevName;
25+
var appsArray = [];
26+
var grSSA = new GlideRecord('sys_store_app');
27+
grSSA.addEncodedQuery('install_dateISNOTEMPTY^hide_on_ui=false^vendor=ServiceNow^ORvendorISEMPTY');
28+
grSSA.orderBy('name');
29+
grSSA.orderBy('version');
30+
grSSA.query();
31+
while (grSSA.next()) {
32+
var curName = grSSA.getValue('name');
33+
var latestVersion = updateAvailable(grSSA);
34+
if (curName == prevName) {
35+
continue;
36+
}
37+
if (latestVersion) {
38+
prevName = curName;
39+
var appObject = {
40+
displayName: curName,
41+
id: grSSA.getUniqueValue(),
42+
load_demo_data: loadDemoData,
43+
type: "application",
44+
requested_version: grSSA.getValue('latest_version')
45+
};
46+
appsArray.push(appObject);
47+
}
48+
}
49+
function updateAvailable(grSSA) {
50+
var installedVersion = grSSA.getValue('version');
51+
var latestVersion = grSSA.getValue('latest_version');
52+
var installedArray = installedVersion.split('.');
53+
var latestArray = latestVersion.split('.');
54+
var len = Math.max(installedArray.length, latestArray.length);
55+
for (var i = 0; i < len; i++) {
56+
var installed = installedArray[i] ? parseInt(installedArray[i]) : 0;
57+
var latest = latestArray[i] ? parseInt(latestArray[i]) : 0;
58+
if (installed < latest) {
59+
return true;
60+
} else if (installed > latest) {
61+
return false;
62+
}
63+
}
64+
return false;
65+
}
66+
if (appsArray.length > 0) {
67+
var appsPackages = {};
68+
appsPackages.packages = appsArray;
69+
appsPackages.name = 'Update Apps';
70+
var data = new global.JSON().encode(appsPackages);
1271
13-
var send_chat = new x_snc_slackerbot.Slacker().send_chat(current, message, true);
72+
var url = gs.getProperty('glide.servlet.uri') +'$restapi.do?ns=sn_cicd&service=CICD%20Batch%20Install%20API&version=latest';
73+
gs.info('\\nOpen the following URL in a new tab:\\n\\n' + url + '\\n\\ncopy/paste the following JSON into the "Raw" Request body\\n\\n' + data);
74+
} else {
75+
gs.info("\\nNo apps to update found.\\nIf you think this is incorrect please try running this script again with `updateCheck` set to `true`. This will check the store for any new updates.\\n\\n(sometimes there are apps in the Application Manager that say that there are updates but you can't actually update them)");
76+
}
77+
`
78+
79+
const message = "<@U6E2TEKQ9> made a cool script for bulk updating apps!\n\n" + eric_script;
80+
81+
new x_snc_slackerbot.Slacker().send_chat(current, message, true);

0 commit comments

Comments
 (0)