Stop prevent to reopen incident when state is closed

siva14
Tera Contributor

Hi All,

 

currently we are using just normal inbound action for reopen incidents, now we have requirement that if we received any reopen mail , if incident is closed, instead of reopen the closed ticket ,want to create new record for that, 

 

Anyone please help me with inbound action script that would be helpful.

 

#inbound action #email #inbound @#script

2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

@siva14 

you need to update the OOB inbound action and check if incident is closed then create a new one

what did you try so far and what's not working?

Did you debug it?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi @Ankur Bawiskar , 

 

sorry for delay in responce, i have used below code, it is not working

 

gs.include('validators');

if (current.getTableName() == "incident") {
    var gr = current;
    if (gr.state != 6) {
        current.state = 2;
        current.comments = "This INC was reopened by the caller.";
    }
else{
      //  gs.eventQueue("incident.Closed", gr, gr.state, previous.state);

        var newincident = new GlideRecord('incident');
        newincident.initialize();
        current.comments = "received from: " + email.origemail + "\n\n" + email.body_text;
        var sid = gs.createUser(email.from);
        var groupSet = false;
        var assigneeSet = false;
        var assignee;
        var group;
        var configItem;

        if (email.body.summary != undefined) {
            current.short_description = email.body.summary;
        } else {
            current.short_description = email.subject;
        }

        if (email.body.description != undefined && email.body.description.trim() != '') {
            Logging.log('email body desc: ' + email.body.description, "Inbound Email Action: Create Incident");
            current.description = email.body.description;
        } else {
            current.description = email.body_text;
        }

        if (email.body.status != undefined) {
            current.state = email.body.status;
        } else {
            current.state = 2; //Assigned
        }

        if (email.body.device != undefined) {
            current.u_device_name = email.body.device;
        }

        current.location = '9776ddb213ba9600b1d6d0322244b094';

        if (email.body.caller != undefined) {
            current.caller_id = email.body.caller;
        } else {
            current.caller_id = sid;
        }

        if (email.body.impact != undefined) {
            if (email.body.impact.toString() != '1') {
                current.impact = email.body.impact;
            } else {
                current.impact = '2';
            }
        }

        if (email.body.urgency != undefined) {
            current.urgency = email.body.urgency;
        }

        if (email.body.assignee != undefined) {
            assignee = email.body.assignee;
            assigneeSet = true;
        }

        if (email.body.group != undefined) {
            group = email.body.group;
            groupSet = true;
        }

        if (groupSet == true) {
            var gr = new GlideRecord('sys_user_group');
            gr.addQuery('name', group);
            gr.query();
            while (gr.next()) {
                group = gr.sys_id;
            }
        }

        if (email.body.item != undefined) {
            var ciName = email.body.item;
            var ci = new GlideRecord('cmdb_ci');
            ci.addQuery('name', ciName);
            ci.query();
            while (ci.next()) {
                current.cmdb_ci = ci.sys_id;
                configItem = ci.sys_id;
                if (groupSet == false) {
                    group = ci.support_group;
                    groupSet = true;
                }
            }
        }

        if (!assigneeSet && configItem) {
            assignee = new LookupOnCall().lookupCurrentOnCall(group.toString(), configItem.toString());
        }

        current.contact_type = 'email';
        current.assigned_to = assignee;
        if (groupSet) {
            current.assignment_group = group;
        } else {
            current.assignment_group = "ca34606013b52a00b1d6b0322244b023"; // Service desk
        }
    }
}


current.insert();