Automatically updating state field when sending email from the record.

peterwigham
Kilo Expert

Hi guys,

I was just wondering if anyone had ever had the same requirements as myself or if anyone could point me in the right direction here.

We have a requirement whereby if a user sends an email from a record using the email client the state of that record should automatically update. For example; if Analyst A is looking at a record but needs more information he can use the email client to email User B. On sending this the email we would like the state to update to 'Awaiting User'.

Does anyone have any idea if this is possible and if so, how this can be achieved?

Thanks in advance,
PW

12 REPLIES 12

If you add the condition gs.hasRole('itil'), it will not fire when a user who does not have that role updates the ticket with an additional comment. Is there a reason on the process side why this will not work? Such as, maybe certain users who have the itil role could also be end users using the incident module?


peterwigham
Kilo Expert

Hi Derek,

Thanks again for the reply. I've tested this two ways; one by adding the script to an existing Business Rule and the other way but setting up an entirely new Business Rule.
The existing business Rule is:

When: BEFORE insert and update.



if (current.operation() != 'insert' && current.comments.changes()) {
gs.eventQueue("incident.commented", current, gs.getUserID(), gs.getUserName());
}

if (current.operation() == 'insert') {
gs.eventQueue("incident.inserted", current, gs.getUserID(), gs.getUserName());
}

if (current.operation() == 'update') {
gs.eventQueue("incident.updated", current, gs.getUserID(), gs.getUserName());
}

if ((current.incident_state == 6) || (current.incident_state == 7)) {
// incident state is closed so
// 1. mark the task as inactive
// 2. set the closed by to current user if not supplied
// 3. set the closed time to now if not supplied
current.active = false;
}


if (!current.assigned_to.nil() && current.assigned_to.changes()) {
gs.eventQueue("incident.assigned", current, current.assigned_to.getDisplayValue() , previous.assigned_to.getDisplayValue());
}

if (!current.assignment_group.nil() && current.assignment_group.changes()) {
gs.eventQueue("incident.assigned.to.group", current, current.assignment_group.getDisplayValue() , previous.assignment_group.getDisplayValue());
}

if (current.incident_state.changes() && current.incident_state == 18) {
gs.eventQueue("incident.awaitingchange", current, current.incident_state, previous.incident_state);
}

if (current.priority.changes() && current.priority == 1) {
gs.eventQueue("incident.priority.1", current, current.priority, previous.priority);
}

if (current.operation() == 'update' && current.priority == 1 && current.state == "Resolved") {
gs.eventQueue("incident.updated", current, gs.getUserID(), gs.getUserName());
}

if (current.category.changes() && current.category == "TCS") {
gs.eventQueue("incident.tcs", current, current.category, previous.category);
}

if (current.severity.changes() && current.severity== 1) {
gs.eventQueue("incident.severity.1", current, current.severity, previous.severity);
}

if (current.escalation.changes() && current.escalation > previous.escalation && previous.escalation != -1) {
gs.eventQueue("incident.escalated", current, current.escalation , previous.escalation );
}

if (current.active.changesTo(false)) {
gs.eventQueue("incident.inactive", current, current.incident_state, previous.incident_state);
gs.workflowFlush(current);
}

if (current.operation() != 'insert' && current.comments.changes() && current.active == true) {
current.incident_state = '8';
}


When I use the script on its own I simply use:

When: BEFORE insert and update.


if (current.operation() != 'insert' && current.comments.changes() && current.active == true) {
current.incident_state = '8';
}


As mentioned, this works fine if I update the record through the 'Additional comment' field however this is not what we want. We want the incident state to update ONLY when the email client is used. If a user updates the record through the 'Additional comment' field we do not want the incident state to update.

Thanks again,
PW


SamuelTse
Tera Guru

I apologize for pumping this old thread up. We are trying to do the exact same thing and I wonder if there is a solution out there. We need to update the record once an email is sent from the email client.

Any input will be greatly appreciated.

Sam


does this do what you want? you said you wanted it to update the ticket..I wasn't sure if that meant work notes or state.


table: email [sys_email]
when: after / update
condition: ((current.target_table == "incident") && (current.sys_mod_count == 1) && (current.sys_created_by != "system"))

script:
var inc_work_notes = "blah...email sent";
var inc_sys_id = current.instance;
var target = new GlideRecord('incident');
target.addQuery('sys_id', inc_sys_id);
target.query(); // Issue the query to the database to get relevant records
while (target.next()) {
target.work_notes = inc_work_notes;
target.update();
}


YES! This works beautifully. Thank you very much for the quick reply and resolution. I actually wonder what this condition does: sys_mod_count == 1?