- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-03-2024 12:31 PM - edited 09-03-2024 12:35 PM
Hello,
we have a inbound action through which incidents will be created. I have a request to capture external email address in a field. Basically, i have to create a field which will capture the external email address. Could anyone help me through this?
inbound email script used:
// Note: current.opened_by is already set to the first UserID that matches the From: email address
current.caller_id = gs.getUserID();
//Set affected user
current.u_affected_user = gs.getUserID();
//Set location to affected user's location
current.location = current.u_affected_user.location;
current.comments = "received from: " + email.origemail + "\n\n" + email.body_text;
current.short_description = email.subject;
//Set description from the email body
//current.category = "inquiry";
current.description = email.body_text;
current.incident_state = IncidentState.NEW;
current.notify = 2;
current.contact_type = "email";
if (email.body.assign != undefined)
current.assigned_to = email.body.assign;
//Only Set the Urgency
if (email.importance != undefined) {
if (email.importance.toLowerCase() == "high") {
//current.impact = 1;
current.urgency = 1;
}
}
if (current.canCreate())
current.insert();
Thank you!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2024 09:53 AM
Hello @Hajar BENJAHHAR ,
Thank you for helping me through this. I tried your script it seems to work but, in our instance, even unknown callers have same "@internalDomain" but when incident is created caller value will be set to "Unknown Guest" as their user id/ email id is not available in user table. we can differentiate them by this. I tried this script it didn't work. could you help me further?
// Convert the email address to a string
var senderEmail = email.origemail.toString();
// Check if the caller is "Unknown Guest"
if (current.caller_id == 'guest' || current.caller_id == 'Unknown Guest') {
// Add the sender's email to the watch list
if (senderEmail) {
current.watch_list = senderEmail;
}
}
Thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2024 01:41 PM
Hello @SM123 ,
I'm in 👍 for the idea of checking if the user exists or not . There is one thing you can do it to optimize the script by using the get method instead of performing a GlideRecord query on the entire table. This is a best practice because get returns a signle record and is ideal for your case as you expect one record or none.
// Convert the email address to a string
var senderEmail = email.origemail.toString();
// Get the sys_user table to check if the sender's email exists
var userGR = new GlideRecord('sys_user');
// If no user is found with this email, add the email to the watch list
if (!userGR.get('email', senderEmail)) {
current.watch_list = senderEmail;
}
// Continue with the rest of the script
Best regards,
Hajar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-03-2024 01:07 PM
Hello @SM123
You can add this code to check whether the email is external or internal :
var senderEmail = email.origemail.toString();
if(senderEmail.indexOf('@internalDomain')<0){
current.custom_field = senderEmail;
}
Best regards,
Hajar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2024 10:16 AM
Hi @Hajar BENJAHHAR ,
thank you for your response. i will try it and will let you know. do i have replace anything in the place of "@internalDamain" ?
thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2024 10:26 AM
Hello @SM123 ,
You only need to replace "@internalDomain" with your internal domain. For example, if your domain is "@servicenow", you would use that in place of "@internalDomain".
Best regards,
Hajar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2024 09:53 AM
Hello @Hajar BENJAHHAR ,
Thank you for helping me through this. I tried your script it seems to work but, in our instance, even unknown callers have same "@internalDomain" but when incident is created caller value will be set to "Unknown Guest" as their user id/ email id is not available in user table. we can differentiate them by this. I tried this script it didn't work. could you help me further?
// Convert the email address to a string
var senderEmail = email.origemail.toString();
// Check if the caller is "Unknown Guest"
if (current.caller_id == 'guest' || current.caller_id == 'Unknown Guest') {
// Add the sender's email to the watch list
if (senderEmail) {
current.watch_list = senderEmail;
}
}
Thank you!