Skip to content

Commit e85fed7

Browse files
authored
Update App Update Script.js (#471)
Updates script to remove the need to use the API Explorer
1 parent e60c9af commit e85fed7

File tree

1 file changed

+47
-20
lines changed

1 file changed

+47
-20
lines changed

Parsers/App Update Script.js

Lines changed: 47 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,34 @@ flags:gmi
77
const eric_script = `
88
\`\`\`
99
/*----------------------------------------------------*/
10-
/* */
10+
/* AUTO */
1111
/* Have a bunch of apps that need to be updated? */
1212
/* Run this and follow the directions in the output */
13-
/* It will build a payload and use the CI/CD API to */
14-
/* run a batch install of all of the needed updates. */
13+
/* It will automaticallybuild and run a batch */
14+
/* install of all of the needed updates. */
15+
/* */
16+
/* Latest code always available at */
17+
/* https://snwizard.com/update-apps */
1518
/* */
1619
/*----------------------------------------------------*/
1720
1821
//Want Demo Data with the app?
1922
var loadDemoData = true;
20-
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
23+
var updateCheck = false; //this can take some time to run and adds a LOT of stuff to the log making the important bit harder to find
2124
22-
if (updateCheck)
23-
new sn_appclient.UpdateChecker().checkAvailableUpdates();
25+
if (updateCheck) new sn_appclient.UpdateChecker().checkAvailableUpdates();
2426
2527
var prevName;
2628
var appsArray = [];
27-
var grSSA = new GlideRecord('sys_store_app');
28-
grSSA.addEncodedQuery('install_dateISNOTEMPTY^hide_on_ui=false^vendor=ServiceNow^ORvendorISEMPTY');
29-
grSSA.orderBy('name');
30-
grSSA.orderBy('version');
29+
var grSSA = new GlideRecord("sys_store_app");
30+
grSSA.addEncodedQuery(
31+
"install_dateISNOTEMPTY^hide_on_ui=false^vendor=ServiceNow^ORvendorISEMPTY"
32+
);
33+
grSSA.orderBy("name");
34+
grSSA.orderBy("version");
3135
grSSA.query();
3236
while (grSSA.next()) {
33-
var curName = grSSA.getValue('name');
37+
var curName = grSSA.getValue("name");
3438
var latestVersion = updateAvailable(grSSA);
3539
if (curName == prevName) {
3640
continue;
@@ -42,16 +46,17 @@ while (grSSA.next()) {
4246
id: grSSA.getUniqueValue(),
4347
load_demo_data: loadDemoData,
4448
type: "application",
45-
requested_version: grSSA.getValue('latest_version')
49+
requested_version: grSSA.getValue("latest_version"),
4650
};
4751
appsArray.push(appObject);
4852
}
4953
}
54+
5055
function updateAvailable(grSSA) {
51-
var installedVersion = grSSA.getValue('version');
52-
var latestVersion = grSSA.getValue('latest_version');
53-
var installedArray = installedVersion.split('.');
54-
var latestArray = latestVersion.split('.');
56+
var installedVersion = grSSA.getValue("version");
57+
var latestVersion = grSSA.getValue("latest_version");
58+
var installedArray = installedVersion.split(".");
59+
var latestArray = latestVersion.split(".");
5560
var len = Math.max(installedArray.length, latestArray.length);
5661
for (var i = 0; i < len; i++) {
5762
var installed = installedArray[i] ? parseInt(installedArray[i]) : 0;
@@ -65,16 +70,38 @@ function updateAvailable(grSSA) {
6570
return false;
6671
}
6772
if (appsArray.length > 0) {
73+
gs.info("\n\n------------------------------------------------\n\nLinks to track progress below the payload information\n\n(scroll down)\n\n-----------------------------------------------\n\n");
74+
6875
var appsPackages = {};
6976
appsPackages.packages = appsArray;
70-
appsPackages.name = 'Update Apps';
77+
appsPackages.name = "Update Apps";
7178
var data = new global.JSON().encode(appsPackages);
7279
73-
var url = gs.getProperty('glide.servlet.uri') +'$restapi.do?ns=sn_cicd&service=CICD%20Batch%20Install%20API&version=latest';
74-
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);
80+
var baseUrl = gs.getProperty("glide.servlet.uri");
81+
var update = new sn_appclient.AppUpgrader().installBatch(data);
82+
var updateObj = JSON.parse(update);
83+
gs.info(
84+
"\n\n------------------------------------------------\n\nOpen the Batch install link to monitor the installation progress. It may take some time for the apps to all populate in the related list. After all apps have populated the install will start and the State will change to In progress.\n\nBatch install:\n" +
85+
baseUrl +
86+
"nav_to.do?uri=sys_batch_install_plan.do?sys_id=" +
87+
updateObj.batch_installation_id +
88+
"\n\nExecution tracker:\n" +
89+
baseUrl +
90+
"nav_to.do?uri=sys_progress_worker.do?sys_id=" +
91+
updateObj.execution_tracker_id +
92+
"\n\n-----------------------------------------------\n\n"
93+
);
94+
var grSBIP = new GlideRecord('sys_batch_install_plan');
95+
if (grSBIP.get(updateObj.batch_installation_id)) {
96+
grSBIP.setValue('notes','It may take some time for the apps to all populate in the related list below (you can refresh the list as needed to see them populating). \n\nAfter all apps have populated the install will start and the State (above) will change to In progress. \n\nWhen the batch is done the state will update to Installed');
97+
grSBIP.update();
98+
}
7599
} else {
76-
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)");
100+
gs.info(
101+
"\n\n-----------------------------------------------\n\nAll apps appear to be up-to-date. \n\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(sometimes there are apps in the Application Manager that say that there are updates but you can't actually update them)\n\n-----------------------------------------------\n\n"
102+
);
77103
}
104+
78105
\`\`\`
79106
`;
80107

0 commit comments

Comments
 (0)