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

Ajay_Chavan
Kilo Sage
Can you try it below?

Trigger: Record Updated
Table: Incident [incident]
Condition: Activity entries updated

Flow Logic:

Look Up Records on sys_email table:

Condition: target = Trigger - Incident Record AND state = sent AND sys_created_on > {{NOW - 2 MINUTES}}


For Each email found:

If email sender = incident assigned_to:

Update Record: Set incident state to "On Hold"
Update Record: Add work notes
Glad I could help! If this solved your issue, please mark it as Helpful and Accept as Solution so others can benefit too.*****Chavan A.P. | Technical Architect | Certified Professional*****

Hey Chavan, 

This might work, but sadly one of the lookups couldn't find anything in the tables. I tried fiddling with it, but sadly didn't get it solved in Flow Designer. Thanks for the guidance and thought process though! 

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/

Hey Kaushal, 

This worked, but kept looping as every time the work notes were updated it kept going, so what I had to do was put in an Event Registration into the business rule that waited for 90,000 MS to kick off that query. This got it solved, thank you!