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

var gr = "User Updated : abel.tuter";
var arr = [];
arr = gr.split(':');
gs.print("Array 1:" + arr[0]);
gs.print("Array 2:" + arr[1] );

 

try to replicate the same with email.subject;

get the email.subject in the variable. 

var grstring = email.subject;

var arr = [];

arr =grstring.split(':');

var callerid = arr[1];

then current.caller_id = callerid;

 

I tried in the background script scripts. It will come like this.

MDAQUIBKHAN_0-1667482587492.png

if the above solution will not work. than try this also 

var gr = new GlideRecord('sys_user');
gr.addQuery('name', callerid.toString()); // Please pick the correct backened value of the username /name . callerid is from the email subject after the split
gr.query(); 
while (gr.next()) {
 current.caller_id = gr.sys_id
}

 

raycallan
Giga Guru

Hi @Hari S1 ,

 

A few questions

  • Is this for all inbound email or only for certain email addresses
  • What is the format of the caller (eg full name, user name, email)
  • Does the subject only contain the caller or doe we need to split the subject to get the caller

Do you have an example of the your subject line looks like

 

You would probably need to script something like this if searching by full name

 

var gr = new GlideRecord('sys_user');
gr.addQuery('name', email.subject);
gr.query(); 
while (gr.next()) {
 current.caller_id = gr.sys_id
}
    

 

Hi Raycallan,

Thanks for the response.

 

1. It is only for one email addresses(Example: xyz@gmail.com), not for all inbound emails.

2. Format of the caller is user name.

3. Yes, the subject contains the caller but the caller id might change(dynamic).

Yes, I have the subject line: Example: User updated User Id: abel.tuter(User Id might changes)

 

I tried the below script but still, the caller is empty.

 

Thank you so much.

try this once 

var grstring = email.subject;

var arr = [];

arr =grstring.split(':');

var callerid = arr[1];

gs.log ('Caller:' +callerid );

var gr = new GlideRecord('sys_user');
gr.addQuery('name', callerid.toString()); // Please pick the correct backened value of the username /name . callerid is from the email subject after the split
gr.query(); 
while (gr.next()) {
 current.caller_id = gr.sys_id;
}

 

Hi @MD AQUIB KHAN 

 

I tried the above script but still, the caller is empty.

 

HariS1_3-1667489015878.png

 

 

 

 

HariS1_2-1667488881003.png