Inbound email action parsing to incident table

jMarshal
Mega Sage
Mega Sage

Hi, I'm hoping someone with good scripting skills can help me -- I will be able to test this and resolve it myself shortly, I'm sure...but unfortunately I don't have access to my test environment right now.

I am trying to write an inbound email action that will parse an email which looks like this:

Hello Support Team,

I have found the following account in error state and taken the following actions:

external Ticket Number

number:<value>

external Ticket Created on

created.<value>

internal User Email

useremail:<value>

initial Notes

notes:<value>

Actions Taken

action:<value>

Further Action needed

next:<value>

 

 

...and my script looks like this:

 

 

 

//var emailAddy = email.useremail;
    //var user = emailAddy;
    // may need a glide record lookup method to bring back a user from an email where it populates the variable "user" with the returned value from the glide record.
    //current.client = user;
    
    // OR
    //current.client = email.useremail; ???
    
    //current.openedby = SYSID OF THE USER who discovered the account
    //current.opened = email.created;
    //current.category = "security services";
    //current.subcategory = "account compromised";
    //current.affected_ci = "user account";
    //current.impact = "individual";
    //current.urgency = "high";
    //current.assignmentgroup = "service desk";
    //current.comments = "<br> external Ticket Number <br>" + email.number + "<br> Created on <br>" + email.created + "<br>initial Notes <br>" + email.notes + "<br> Actions Taken <br>" + email.action + "<br> Further Action <br>" + email.next;
    //current.worknotes = "<br> Inbound email from email.example@service-now.com below <br>" + email.body;
    // current.update(); <-- may want to consider not using if only using for insert, which we probably are. ??

 

can anyone please confirm if this script will work as I seem to expect it will, once I comment it out...?

To be clear, I'm aware that the variable names may not be correct, I'm more so just after info if I'll need a Glide Record lookup or something...or perhaps I'm missing something else?

Any kind of tips from a scripting wizard would be appreciated and then when I get access to my test environment again, I can be better prepared.

Thanks in advance!! Always willing to provide great feedback/reviews to good community users...and can offer advice in trade related to ITSM best practice with some practical examples, if needed.

1 ACCEPTED SOLUTION

Hi James,

For your scenario, Yes you can achieve the requirement. You can add below script and fine tune depends your requirement

var email_id = email.from;

var grUser = new GlideRecord('sys_user');

grUser.addQuery('email',email_id);

grUser.query();

if(grUser.next()){

current.caller_id = grUser.sys_id;

current.u_impacted_user = grUser.sys_id;

}

Similarly, you can restrict the email update who is having an account or email id is not properly configured. For this scenario you can use condition field under when to run tab else you control directly in the script.

find_real_file.png

Please mark it as the correct answer if it helped.

Regards,

Suresh.

Regards,
Suresh.

View solution in original post

4 REPLIES 4

ersureshbe
Giga Sage
Giga Sage

Hi,

We have OOB scripts to create the incident and update the incident based on email. You just use that and I can see some additional fields should be populated based on your requirement.

 To set the value always DB value of the choice.

    //current.category = "security services";
    //current.subcategory = "account compromised";
    //current.affected_ci = "user account";
    //current.impact = "individual";
    //current.urgency = "high";

 

find_real_file.png

Regards,

Suresh.

Regards,
Suresh.

Thanks for your reply.

To be clear, the sender email will NOT be the affected user. The sender is NOT the "caller_id" value on the incident...which is what the ootb method you're describing assumes, I believe.

I'm still using the ootb method for parsing variables "on the fly" out of an email body, to get the information about the email address of the affected account, which I then want to set as the "caller_id" (the user who is associated in the sysuser table with the email address in the body of the email -- "email.useremail"). https://docs.servicenow.com/bundle/sandiego-servicenow-platform/page/administer/notification/referen...

 

What I'm more concerned with, is if I need to use a glide script to get the user info from the email address provided in the body of the email sent...to then assign as the "caller_id"...or if I can just use the email address as the value for "caller_id" and servicenow will fill in the gaps...

...the later would be great and easy enough to discover, but as I described, I"m just trying to be prepared in advance, if possible.

 

Hi James,

For your scenario, Yes you can achieve the requirement. You can add below script and fine tune depends your requirement

var email_id = email.from;

var grUser = new GlideRecord('sys_user');

grUser.addQuery('email',email_id);

grUser.query();

if(grUser.next()){

current.caller_id = grUser.sys_id;

current.u_impacted_user = grUser.sys_id;

}

Similarly, you can restrict the email update who is having an account or email id is not properly configured. For this scenario you can use condition field under when to run tab else you control directly in the script.

find_real_file.png

Please mark it as the correct answer if it helped.

Regards,

Suresh.

Regards,
Suresh.

Thank you so much Suresh! This was exactly what I suspected and was looking for. Thank you for taking the time to be thorough with the response and following up!