The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Change Incident State from Outbound Email

Richard22
Tera Expert

Hi ServiceNow Community,

I’m working on a business rule or a flow to automatically update the state of an Incident to "On Hold" when a technician sends an email using the ServiceNow email client in Incident Management. Despite my efforts, the rule isn’t functioning as expected, and I’m hoping someone can provide guidance or share their experience with similar implementations.


Details of My Use Case:

  1. How Emails Are Sent:

    • Emails are sent using the email client in ServiceNow Incident Management.
    • These emails are not draft emails—they are directly sent and move to the "sent" state in the sys_email table.

  2. What I’m Trying to Achieve:

    • When an email is sent from an Incident, I want to check if the sender (user_id in sys_email) matches the assigned_to field on the Incident.
    • If they match, the Incident’s state should be updated to "On Hold," and a work note should be added for tracking purposes.

  3. Challenges Encountered (business rule):

    • The business rule is set to run on the sys_email table, triggered After Insert.
    • I’ve tried using the target_table field in the sys_email record as a condition (current.target_table == 'incident'), but the rule doesn’t seem to trigger or execute properly.
    • The sender will always be different for each email, but the email template remains the same.

  4. Challenges Encountered (flow):
    • I can check if there is activity in an incident, but if even one email is sent, the rule executes, I cannot check the last activity. 
    • I cannot pull directly from the sys_email table which would be the easiest option, hwoever, is not selectable in trigger. 

  5. What I’ve Tried:

    • Baking the target table check into the script itself, rather than relying on the condition in the business rule.
    • Adding debug logs to identify where the script might be failing and within Flow Designer, but the triggers never even happen.
    • Testing emails with different configurations (e.g., checking draft emails, verifying user_id, etc.).
    • Ensuring the state value for "On Hold" (3) matches the configuration in my instance.
1 ACCEPTED SOLUTION

kaushal_snow
Mega Sage

Hi @Richard22 .

 

Try this out by  creating a business rule on incident table....

 

Trigger: After Update on Incident

Condition: assigned_to is unchanged

 

var gr = new GlideRecord('sys_email');
gr.addQuery('target', current.sys_id);
gr.addQuery('state', 'sent');
gr.addQuery('sys_created_on', '>=', gs.minutesAgo(2));
gr.query();
while (gr.next()) {
if (gr.user_id == current.assigned_to) {
current.setValue('state', 3); // On Hold
current.work_notes = "Placed On Hold due to outbound email by assigned technician";
current.update();
break;
}
}

If you found my response helpful, please mark it as ‘Accept as Solution’ and ‘Helpful’. This helps other community members find the right answer more easily and supports the community.

 

Thanks and Regards,
Kaushal Kumar Jha - ServiceNow Consultant - Lets connect on Linkedin: https://www.linkedin.com/in/kaushalkrjha/

View solution in original post

5 REPLIES 5

Bhuvan
Kilo Patron

@Richard22 

 

This would be easier to manage via Flow if you do not have any license restrictions. This would be a no code approach and would be better for manageability & upgradeability and you can easily introduce additional functions if needed in future without relying on coding.

 

If you would like to implement, try below

 

1. Create a Flow with trigger on sys_email table with filter conditions 'user_id' is not empty and 'target_table' is incident. This would help to fire the flow only for user triggered email notifications for incident table. System notifications will have user_id as empty

 

2. Create a lookup on incident table where sys_email.instance = incident.sys_id

 

3. Create a Flow Logic IF condition to check incident.assigned_to = sys_email.user_id 

 

4. If it evaluates to true, use update record action to change the incident state to 'On Hold'

 

If you face any challenges, share the Flow details and can help to resolve it.

 

As per community guidelines, you can accept more than one answer as accepted solution. If my response helped to answer your query, please mark it helpful & accept the solution.

 

Thanks,

Bhuvan