Create incidents from external users by mail

Hichem
Mega Expert

Hello,

I'm trying to allow external users to create incidents through emails (whitout having accounts).

I've found in this forum below code snippet.
The inbound email action successfully create an incident, but nothing in user and caller fields.
What I want is to populate these fields with Guest user if email sender is not found in the sys_user table and add in a specific field "u_guest_email" sender email.

Any help would be greatly appreciated

Thanks

-----------------------------------
current.comments = "received from: " + email.origemail + "\n\n" + email.body_text;
current.short_description = email.subject;

var eto = email.to.toLowerCase().toString();
// var sid = gs.createUser(email.from);
var sid;
var rec = new GlideRecord('sys_user');
rec.addQuery('email',email.from);
rec.query();
rec.next();

if(rec.sys_id != "") {
sid = rec.sys_id;
} else {
gs.getUser();
sid = gs.getUserById('guest').sys_id;
}

current.caller_id = sid;
current.opened_by = sid;
//current.watch_list = email.from;
current.state = 1;
//current.notify = 2;
current.contact_type = "email";

//if(eto.indexOf("accounts") > -1){
//current.assignment_group.setDisplayValue('Account Support');
//}
//else{
//current.assignment_group.setDisplayValue('Consulting');
//}

current.insert();
-----------------------------------

17 REPLIES 17

Hi Hichem,



In your Inbound Email Action, you can copy the original sender's email address from "email.origemail" to the watch_list for your Incident/etc.:



        current.watch_list = email.origemail.toString();



You could also copy it to a custom contact email field, if you had added one to the Task or Incident tables.   The watch list is easiest since it's already in use for notifications.




Thanks,


-Brian


i want to resolve incident based on email i received from user with subject close.i need to check the subcategory field before resolving?can you please help to sort out this?


Hi Soorya,



Not sure to understand exactly your request, but you can try to follow step by step my answer to clinton above.



To check if you have the word close in the subject, you can use :



email.subject.indexOf("close") == 0



if your subcategory is in your email body, you can check for it and add a condition to resolve you incident or not.



Hope this can help