Skip to content

Commit 3a27bd5

Browse files
authored
Auto Upgrade store applications (#2315)
* Create Readme.md * Create script.js * Create sysproperty.js
1 parent 2671acf commit 3a27bd5

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
This script will automatically upgrade the Store applications of your choice, based on a system property.
2+
3+
A few key points about this approach:
4+
• The script upgrades only the applications listed in the system property (auto_upgrade_store_apps) and applications that are included as child.
5+
• It can be scheduled to run automatically or triggered manually.
6+
• You can add an email notification, a banner, or another form of alert to notify admins about which applications were updated.
7+
8+
This is a simple way to save time and keep Store applications up to date without manual intervention.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
upgradeSelectedStoreApps();
2+
3+
function upgradeSelectedStoreApps() {
4+
var propertyName = "auto_upgrade_store_apps";
5+
var storeAppsList = gs.getProperty(propertyName, "");
6+
if (!storeAppsList) {
7+
gs.info("No store applications listed for auto-upgrade.");
8+
return;
9+
}
10+
var appsToUpgrade = storeAppsList.split(",").map(function(app) {
11+
return app.trim();
12+
});
13+
var upgradedApps = [];
14+
var storeAppGr = new GlideRecord('sys_store_app');
15+
storeAppGr.addQuery('active', true); // Only active store applications
16+
storeAppGr.addQuery('sys_id', 'IN', appsToUpgrade); // Filter by system property list
17+
storeAppGr.query();
18+
while (storeAppGr.next()) {
19+
var appId = storeAppGr.getValue('sys_id');
20+
var appName = storeAppGr.getValue('name');
21+
var currentVersion = storeAppGr.getValue('version');
22+
var availableVersion = storeAppGr.getValue('latest_version');
23+
if (availableVersion && currentVersion !== availableVersion) {
24+
try {
25+
gs.info('Upgrading store application: ' + appName + ' from version ' + currentVersion + ' to ' + availableVersion);
26+
var worker = new sn_appclient.AppUpgrader();
27+
storeUpgradeResult = worker.upgrade(appId.toString(), availableVersion.toString(), false);
28+
if (storeUpgradeResult) {
29+
gs.info('Store application "' + appName + '" upgraded successfully.');
30+
upgradedApps.push({
31+
name: appName,
32+
fromVersion: currentVersion,
33+
toVersion: availableVersion
34+
});
35+
} else {
36+
gs.error('Failed to upgrade store application: ' + appName);
37+
}
38+
} catch (e) {
39+
gs.error('Error upgrading store application "' + appName + '": ' + e.message);
40+
}
41+
} else {
42+
gs.info('Store application "' + appName + '" is already up-to-date.');
43+
}
44+
}
45+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/*
2+
create below system property sys_properties table and set sys id for store applications - eg 31774a2953839110a6f8ddeeff7b12cb
3+
*/
4+
5+
auto_upgrade_store_apps

0 commit comments

Comments
 (0)