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();