How to set the caller id from email inbound action

Hari S1
Tera Contributor

Hi,

 

We are trying to get the caller id from the email subject of the inbound action email and set it as a caller for the incident.

 

Thanks for any help.

2 ACCEPTED SOLUTIONS

Hi @Hari S1 

 

This should work for you

 

if (email.origemail == '[email_address]') {
        var arrSubject = email.subject.split(' : '); //need to include the 
        var gr = new GlideRecord('sys_user');
        gr.addQuery('user_name', arrSubject[1]);
        gr.query();
        if (gr.next()) {
            current.caller_id = gr.sys_id
        }
    } else {
        current.caller_id = gs.getUserID();
    }

 

View solution in original post

You need to replace [email_address] with the email address that the email is coming from

Its also a good idea during testing to log what is happening to make it easier to troubleshoot 

For example insert the following at line 3

gs.log ('Caller: ' + arrSubject[1]);

 

View solution in original post

16 REPLIES 16

Make sure to add trim() at the end, otherwise it won't work if the subject has more than one space after the colon character. Example: "User updated User Id   :    abel.tuter" 

 

gr.addQuery('user_name', arrSubject[1].trim());

 


If I helped you with your case, please click the Thumb Icon and mark as Correct.


Sebas Di Loreto
Kilo Sage
Kilo Sage

I think you are getting confused on how you are testing.

The "When to run" TYPE of the inbound action is important if you are testing as a new, reply or forward email.

I assume your intention is to CREATE a NEW incident when a NEW email comes in AND look for the caller_id on the subject line.

Then I suggest to use this out of the box email inbound action as your starting point: /sysevent_in_email_action.do?sys_id=3ccfeff5c611227a0180144333c87af9

And replace the script with:

 

SebastianDL_0-1667495990881.png

 

var userId = [];
userId = email.subject.split(':');
var caller = new GlideRecord('sys_user');
caller.addEncodedQuery('user_name=' + userId[1].trim());
caller.query();
if (caller.next())
      current.caller_id = caller.sys_id;

 

current.short_description = email.subject;
current.description = email.subject;
current.state = IncidentState.NEW;
current.contact_type = "email";
current.insert();

 

Then send a NEW email to your instance with subject "    user  updated  :   abel.tuter   " (leave spaces everywhere to prove the point that works) AND anything on the body of the email.

Then monitor the RECEIVED emails (type that in left nav) for the email and you will be able to diagnose everything that is being processed on that email.

 

 


If I helped you with your case, please click the Thumb Icon and mark as Correct.