Inbound Action - Need to set "Opened by" to the "From" header in the body of a forwarded email
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-04-2022 11:22 AM
I'm forwarding an email to our SN instance and it's creating a request with the "Opened by" set to my name. Is it possible for me to set it to set it to John Smith from the header information here in the email body? Also can I set it to where if John Smith isn't a user in our ServiceNow instance that it will then default to me, the sender?
Right now I'm using this in the script of my Inbound Action
current.opened_by = gs.getUserID();
current.short_description = email.subject;
current.description= email.body_text;
current.comments = "received from: " + email.origemail + "\n\n" + email.body_text;

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-04-2022 11:57 AM
Hi,
You'd need to query your sys_user table using the email.origemail (which would be the original sender) to find a possible match, then if not found, use you...so script would be something like:
var u;
var gr = new GlideRecord('sys_user');
gr.addQuery('email', email.origemail);
gr.query();
if (gr.next()) {
u = gr.getValue('sys_id');
} else {
u = gs.getUserID();
}
current.opened_by = u;
current.short_description = email.subject;
current.description= email.body_text;
current.comments = "received from: " + email.origemail + "\n\n" + email.body_text;
There are times where email.origemail isn't pulling the original sender, if that's the case, then you'll have to adjust the script with something like:
var u;
var str = email.body.from;
var subStr = str.substring(str.lastIndexOf("<") + 1,str.lastIndexOf(">"));
var gr = new GlideRecord('sys_user');
gr.addQuery('email', subStr);
gr.query();
if (gr.next()) {
u = gr.getValue('sys_id');
} else {
u = gs.getUserID();
}
current.opened_by = u;
current.short_description = email.subject;
current.description= email.body_text;
current.comments = "received from: " + email.origemail + "\n\n" + email.body_text;
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!