UI Action for “Run Archive Now” – Getting error with GlideArchiver.runRule
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
8 hours ago
Hi Community,
I am trying to build a custom UI Action on the sys_archive table to trigger an archive rule manually.
My use case is:
First, reassign inactive users to active ones using a custom Script Include UserReassignmentUtil
Then, execute the selected archive rule.
Here’s my script:
(function executeAction(current) {
try {
gs.info("Run Archive Now button clicked...");
// --- 1. Reassign inactive users first ---
var util = new UserReassignmentUtil(); // Your Script Include
var inactiveUser = new GlideRecord("sys_user");
inactiveUser.addQuery("active", false);
inactiveUser.query();
var count = 0;
gs.info("Inactive user count: " + inactiveUser.getRowCount());
while (inactiveUser.next()) {
util.reassignFromInactiveToActive(inactiveUser);
count++;
}
if (count > 0) {
gs.addInfoMessage("Reassignment executed successfully for " + count + " inactive users.");
} else {
gs.addInfoMessage("No inactive users found for reassignment.");
}
// --- 2. Run Archive Rule after reassignment ---
if (current && current.getTableName() === "sys_archive") {
var ruleId = current.sys_id.toString();
gs.info("Executing archive rule ID: " + ruleId);
var ruleGR = new GlideRecord("sys_archive");
if (ruleGR.get(ruleId) && ruleGR.active) {
// GlideArchiver.runRule(ruleId);
var archiver = new GlideArchiveManager();
archiver.archive(ruleId);
gs.addInfoMessage("Archive Rule executed successfully for rule: " + current.name);
} else {
gs.addErrorMessage("Archive Rule is inactive or not found.");
}
} else {
gs.addErrorMessage("This UI Action must be run from the Archive Rule record form.");
}
} catch (e) {
gs.error("Error in Run Archive Now: " + e);
gs.addErrorMessage("Failed to reassign users or run archive rule. Check logs for details.");
}
})(current);
When I click the Run Archive Now button, I get the errors in log I have attached please have a look.
My Questions:
Is GlideArchiver.runRule(ruleId) no longer supported?
What is the correct API to programmatically trigger an archive rule from a script/UI Action?
Is GlideArchiveManager().archive(ruleId) the recommended approach in recent versions?
Any guidance or examples would be greatly appreciated.