Name
global.RevertUpdateVersionAjax
Description
Ajax helper class for helping the Revert UI action on Update Version entries.
Script
var RevertUpdateVersionAjax = Class.create();
RevertUpdateVersionAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, {
revert: function () {
// prevent transaction cancellation by quota rules
var t = null;
var isUncancelable = false;
try {
t = GlideTransaction.get();
if (t != null) {
isUncancelable = t.isUncancelable();
t.setCannotCancel(true);
}
// Secured.
if (!gs.hasRole('admin') && !gs.hasRole('delegated_developer')) {
gs.logWarning("Security restricted: cannot execute", "RevertUpdateVersionAjax.revert");
return;
}
var sys_id = this.getParameter('sysparm_sys_id');
var versionAPI = new GlideappUpdateVersion();
var isReverted = versionAPI.revert(sys_id);
// Notify the user with the appropriate message when the entry could not be reverted
// or a success message if able to revert.
versionAPI.addUINotification();
} finally {
if (t != null)
t.setCannotCancel(isUncancelable);
}
},
revertToBaseSystem : function (sys_id) {
// prevent transaction cancellation by quota rules
var t = null;
var isUncancelable = false;
try {
t = GlideTransaction.get();
if (t != null) {
isUncancelable = t.isUncancelable();
t.setCannotCancel(true);
}
if (typeof sys_id === "undefined")
sys_id = this.getParameter('sysparm_sys_id');
var current = new GlideRecordSecure('sys_upgrade_history_log');
current.get(sys_id);
var name = current.file_name;
var grHead = GlideappUpdateVersion.getHeadVersion(name);
if (grHead.isValidRecord()) {
current.payload = grHead.payload;
}
// if the record is from a store app, the baseline version has its source_table and source set to sys_store_app and the app ID
var storeAppID = GlideappUpdateVersion.getStoreAppID(current);
var grBaselineHead;
if (storeAppID != null)
grBaselineHead = GlideappUpdateVersion.getVersion(name, storeAppID, "sys_store_app", null);
else
grBaselineHead = GlideappUpdateVersion.getVersion(name, current.upgrade_history, "sys_upgrade_history", null);
if (grBaselineHead.isValidRecord()) {
var guv = new GlideappUpdateVersion();
var isSuccess = guv.revert(grBaselineHead.sys_id);
guv.addUINotification();
if (isSuccess) {
current.disposition = '5';
current.resolution_status = 'reviewed_reverted';
current.update();
}
} else {
var gr = new GlideRecordSecure('sys_upgrade_history');
gr.get(current.upgrade_history);
var uin = new UINotification();
uin.setText(gs.getMessage('Your update version entry cannot be reverted because no base system version was found for upgrade {0}', gr.getValue('to_version')));
uin.send();
}
} finally {
if (t != null)
t.setCannotCancel(isUncancelable);
}
},
toString: function () {
return 'RevertUpdateVersionAjax';
}
});
Sys ID
fe7c15311f301000dada97c0ed8b7066