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

RaghavSh
Kilo Patron

You get the caller from email.from objevt , from that email you can get the sys_id of user by gliding the user table.

If you are getting something specific in the email, then it should be at a defined place , like the subject should start with caller id. In that case you can perform string operations on the email.subject and get the caller id.


Raghav
MVP 2023

MD AQUIB KHAN
Giga Guru

Hi,

I guess this is what you are looking for 

current.caller_id = email.subject;

Please share any scripts if you have 

 

Hi Aquib,

Thanks for the quick replay.

 

I sent an email to ServiceNow to create an incident in Servicenow and I mentioned the user Id in the email Subject but still no caller in the incident form. 

 

HariS1_0-1667481507643.png

 

 

Inbound action:

HariS1_1-1667481764200.png

 

 

 

Thanks.