Using username from inbound email action to fill in Caller field.

gnunez
Kilo Guru

I currently use an inbound email action that captures the email in a web form outside of ServiceNow, but if the email isn't in a certain format it won't recognize who the caller is and will leave as blank. To avoid this I am trying to find a way to add to the script so it can capture the information using the username field. Is there any way to do this?

Thanks again!

1 ACCEPTED SOLUTION

Caller field is captured now. Had to add value pairs and then add that to the inbound action for Create Incident.


View solution in original post

44 REPLIES 44

Instead of the script I provided before, you can use this to identify the user, assuming you're still capturing email address and the 'cin_employee_id field holds the employee_id in the sys_user table':



if (gs.getUserDisplayName() == 'Guest' && email.body.cin_employee_id) {   // sender couldn't be resolved to a user but cin_employee_id is provided


  var grUser = new GlideRecord('sys_user');


  grUser.addQuery('cin_employee_id', email.body.cin_employee_id);   // find matching email.body.cin_employee_id


  grUser.query();


  if (grUser.next()) current.caller_id = grUser.sys_id.toString();   // user found using cin_employee_id


}



If you will no longer capture email address, you can simply use



if (email.body.cin_employee_id) {   // identify user using cin_employee_id


  var grUser = new GlideRecord('sys_user');


  grUser.addQuery('cin_employee_id', email.body.cin_employee_id);   // find matching email.body.cin_employee_id


  grUser.query();


  if (grUser.next()) current.caller_id = grUser.sys_id.toString();   // user found using cin_employee_id


}



You'll also need to decide what to do in case the user can't be identified using either their email address or cin_employee_id.


Thank you for the script! I am using the one that no longer captures the email address. It is working the only problem is that the recipient/caller defaults to "Kyle", with the requestor's information in the comment section, username, CIN/Employee ID and Phone Number. (Screenshot of this found below)


find_real_file.png


find_real_file.png


In the script I provided, can you change Line 5 to (or comment out Line 5 and add this below it)



current.short_description = grUser.next() ? grUser.sys_id.toString() : 'User not found for ' + email.body.cin_employee_id;  



This will populate Short Description with data we can use for debugging.


I tested and now the caller field is empty and doesn't default to Kyle anymore. The short description didn't provide any data.


I also noticed the CIN/Employee ID isn't being captured.