Inbound action script is not handling exceptions

GAyathri33
Tera Contributor

Hi Team,

 

Its a bit high priority and provide your solution.

 Written inbound action, without exceptions code is working fine, but if I write exceptions and evenQueue, it is not handling the exceptions and inbound action is not processed.  Please check below code of mine and provide your solutions as soon as possible.

******Code*************

var excp = "";
var existingUsers = [];
var processedUsers = [];

if (email.subject.indexOf("PingCo NOC User List for Visibility Group Automation") !== -1) {
    var userGR = new GlideRecord("sys_user");
    userGR.addQuery("company.name", "TCAP PingCo");
    userGR.query();
    while (userGR.next()) {
        existingUsers.push(userGR.user_name.toString());
    }
    gs.log("Existing PingCo users retrieved");


    var emailGR = new GlideRecord("sys_email");
    emailGR.addQuery("subject", "LIKE", "%PingCo NOC User List for Visibility Group Automation%");
    emailGR.orderByDesc("sys_created_on");
    emailGR.setLimit(1);
    emailGR.query();

    if (emailGR.next()) {
        gs.log("PingCo email processed");
        var emailSysId = emailGR.getUniqueValue();
        gs.log("PingCo email sys_id" + emailSysId);
        var attachmentGR = new GlideRecord("sys_attachment");
        attachmentGR.addQuery("table_name", "sys_email");
        attachmentGR.addQuery("table_sys_id", emailSysId);
        // attachmentGR.addQuery("content_type", "text/csv");
        attachmentGR.orderByDesc("sys_created_on");
        attachmentGR.query();
        gs.log("PingCo attachemtn processed");
        if (attachmentGR.next()) {
            var gsa = new GlideSysAttachment();
            var attachmentData = gsa.getBytes(attachmentGR);
            var attachment = String(Packages.java.lang.String(attachmentData));
            var lines = attachment.split('\n');
            for (var i = 0; i < lines.length; i++) {
                var userId = lines[i].trim();
                // }
                if (userId && userId.indexOf("ID") === -1) {
                    gs.log("PingCo attachment read");
                    processedUsers.push(userId);
                    if (existingUsers.includes(userId)) {
                        var activeUser = new GlideRecord("sys_user");
                        activeUser.addQuery("user_name", userId);
                        activeUser.query();
                        if (activeUser.next()) {
                            activeUser.active = true;
                            activeUser.update();
                            gs.log("PingCo Reactivated user: " + userId);
                        }
                    } else {
                        var newUser = new GlideRecord("sys_user");
                        newUser.initialize();
                        newUser.user_name = userId;
                        newUser.company.setDisplayValue("TCAP PingCo");
                        newUser.active = true;
                        newUser.insert();
                        gs.log("PingCo Created new user: " + userId);
                    }
                }
            }

            for (var j = 0; j < existingUsers.length; j++) {
                var existingUserId = existingUsers[j];
                if (!processedUsers.includes(existingUserId)) {
                    var inactiveUser = new GlideRecord("sys_user");
                    inactiveUser.addQuery("user_name", existingUserId);
                    inactiveUser.query();
                    if (inactiveUser.next()) {
                        inactiveUser.active = false;
                        inactiveUser.update();
                        gs.log("PingCo Marked inactive: " + existingUserId);
                    }
                }
            }
        } else {
            excp += "No CSV attachment found in the email.\n";
        }
    } else {
        excp += "No matching email found.\n";
    }
} else {
    excp += "Email Subject is Wrong. \n";
}
gs.eventQueue("tcap.error", current, email.subject, '');

 

************end************** 

6 REPLIES 6

GAyathri33
Tera Contributor

in Logs, getting only gs.log messages thats it - why notification is not triggering

 

gayathridev
Tera Contributor

Not yet resolve the issue, please provide the correct code please