You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Parsers/App Update Script.js
+73-1Lines changed: 73 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,79 @@ regex:!newline
4
4
flags:gmi
5
5
*/
6
6
7
-
consteric_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}```";
7
+
//const eric_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}```";
var latestVersion = grSSA.getValue('latest_version');
54
+
var installedArray = installedVersion.split('.');
55
+
var latestArray = latestVersion.split('.');
56
+
var len = Math.max(installedArray.length, latestArray.length);
57
+
for (var i = 0; i < len; i++) {
58
+
var installed = installedArray[i] ? parseInt(installedArray[i]) : 0;
59
+
var latest = latestArray[i] ? parseInt(latestArray[i]) : 0;
60
+
if (installed < latest) {
61
+
return true;
62
+
} else if (installed > latest) {
63
+
return false;
64
+
}
65
+
}
66
+
return false;
67
+
}
68
+
if (appsArray.length > 0) {
69
+
var appsPackages = {};
70
+
appsPackages.packages = appsArray;
71
+
appsPackages.name = 'Update Apps';
72
+
var data = new global.JSON().encode(appsPackages);
73
+
74
+
var url = gs.getProperty('glide.servlet.uri') +'$restapi.do?ns=sn_cicd&service=CICD%20Batch%20Install%20API&version=latest';
75
+
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);
76
+
} else {
77
+
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)");
78
+
}
79
+
`;
8
80
9
81
constmessage="<@U6E2TEKQ9> made a cool script for bulk updating apps!\n\n"+eric_script;
0 commit comments