Change caller_id from email field in Inbound Email Action? [Geneva]

jnovack
Kilo Guru

Greetings!

Is there a way to use email fields to set the caller of the Incident? Can a query be crafted within the Inbound Email Action to take the field, search the users table on it, and return the sys_id required?   I'm a complete novice to ServiceNow's JavaScript/Glide implementation, I might need some handholding in terms of writing this script.

I have found that I can automatically assign an ITIL user to the ticket upon creation with the following code:

if (email.body.assign != undefined)

      current.assigned_to = email.body.assign;

I want to use this same style of assignment within the Inbound Email Actions to assign a caller_id.

Unfortunately, it seems that caller_id is looking for the sys_id of the user, as I realized setting it directly (current.caller_id = email.body.caller) did not work, and getUserId() does not take any parameters (getUserId(username) doesn't work), only uses the 'current user' context (which in this case will be the forwarder or FROM of the email).

Raison d'etre: Users are stupid, and thus my help desk and admins get emails to their accounts asking for help.   I'd like to passive-aggressively forward these off to ServiceNow with a "caller" email field so that ServiceNow will automatically create the ticket on the USER's behalf, rather than the ADMIN's behalf.

assign:helpdesk

caller:joe.user

I appreciate you helping me, and at the very least, reading this far!

1 ACCEPTED SOLUTION

Chuck Tomasi
Tera Patron

Hi Justin,



Yes, you can do this. If you have a valid value of the user_name (login) field, you can easily get the sys_id of that user and save it to the caller_id field.



var c = new GlideRecord('sys_user');


if (c.get('user_name', email.body.caller_id)


        current.caller_id = c.getValue('sys_id');



Note: this is untested code and makes some assumptions based on your description and example.


View solution in original post

7 REPLIES 7

Chuck Tomasi
Tera Patron

Hi Justin,



Yes, you can do this. If you have a valid value of the user_name (login) field, you can easily get the sys_id of that user and save it to the caller_id field.



var c = new GlideRecord('sys_user');


if (c.get('user_name', email.body.caller_id)


        current.caller_id = c.getValue('sys_id');



Note: this is untested code and makes some assumptions based on your description and example.


Chuck,



The following code works.   (Corrected field name and added a close paren).


   


if (email.body.caller != undefined) {


var c = new GlideRecord('sys_user');


if (c.get('user_name', email.body.caller))


current.caller_id = c.getValue('sys_id');


}



Thank you very much for responding and for giving me an example to kick off from.



For those playing along.   I added this code to "Create Incident" and "Update Incident".   Within "Create Incident", I added the code above under a new gs.hasRole('itil') code-block conditional so that non-ITIL users cannot create tickets or assign them.   Under "Update Incident", there was already such conditional.



P.S. Great lab presentation at #Knowledge16


Hi Justin, thanks for this post. I too am trying to set the Customer (caller_id) field on our incident form via body text of inbound email. As per above thread I have the below in the Script box of the Actions tab:

if (email.body.caller != undefined) {
var c = new GlideRecord('sys_user');
if (c.get('user_name', email.body.caller))
current.caller_id = c.getValue('sys_id');
}

I am also setting various other field values using the 'Field actions' e.g.

Priority To P3 - High

Type To Incident

Etc.

However I cannot get the caller_id field setting on the incident.

In the body text of test emails I have tried different things such as e.g.

user_name: jty

user_name: JTY

Test emails are being sent by me (who is a user on the sys_user table) - for testing purposes this new inbound action only triggers when sent from me i.e. on the When to run tab the 'From' field has my user record value there (in case any of this makes any difference).

Any help much appreciated! Many thanks.

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Justin,



Use current.caller_id.setDisplayValue(email.body.caller); //Please note for reference field this has to be display value of the field.


Please refer section 4 for more info on this.


http://wiki.servicenow.com/index.php?title=GlideRecord#setDisplayValue