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

Hi ,

 put some log to check what values are you getting .

gs.log('Email Subject" +grstring);

check after that 

like gs.log( "Caller id : " + callerID); gs.log( " Current Caller id : " + current.caller_id);

Also check if your code is working inside the loop . Try to replace the line gr.addQuery('name', callerID);

Try buddy it will work . Follow the steps . Go to Logs and Validate 

 

 

 

 

Hi @MD AQUIB KHAN ,

 

I tried after updating 8th line with "user_name" and adding logs. caller is undefined showing in the logs.

 

HariS1_0-1667493379290.png

 

System logs:

 

HariS1_1-1667493418623.png

 

2. 

 

HariS1_2-1667493452199.png

 

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();
    }

 

Hi @raycallan,

 

I am getting the short description and description but still, the caller is empty.

 

HariS1_0-1667488262731.png

 

Inbound action: I also tried adding "User updated User Id: " in the 2nd line of the script.

 

HariS1_1-1667488555447.png

 

 

 

 

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]);