Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

UI Action for “Run Archive Now” – Getting error with GlideArchiver.runRule

dkgopi123
Tera Contributor

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:

  1. First, reassign inactive users to active ones using a custom Script Include UserReassignmentUtil

  2. 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:

  1. Is GlideArchiver.runRule(ruleId) no longer supported?

  2. What is the correct API to programmatically trigger an archive rule from a script/UI Action?

  3. Is GlideArchiveManager().archive(ruleId) the recommended approach in recent versions?

Any guidance or examples would be greatly appreciated. 

 

0 REPLIES 0