inbound email action

shivaadapa
Tera Expert

Hi

help me to create inbound email action with the below requirement and in the action script what should i write?

"Create incident from email, with the following feature.

    1. If caller is VIP caller, route ticket to "VIP Support Group" & Set Priority as = P2"
4 REPLIES 4

M Ismail
Tera Guru

Hi @shivaadapa ,
You can do this by 

  1. Configure the Inbound Email Action:

    • Navigate to "System Policy" > "Inbound Email" > "Inbound Actions".
    • Create a new inbound email action.
  2. Write the Action Script:

    • In the action script, write this code 
      var email = new GlideEmailInbound();
      email.initialize();
      var senderEmail = email.getHeaderFrom();
      var caller = new GlideRecord('sys_user');
      caller.addQuery('email', senderEmail);
      caller.query();
      if (caller.next()) {
      var isVIP = caller.getValue('vip');
      var incident = new GlideRecord('incident');
      incident.initialize();
      incident.caller_id = caller.getUniqueValue();
      if (isVIP) {
      incident.priority = 2;
      incident.assignment_group = 'VIP Support Group';
      } else {
      incident.priority = 3;
      }
      incident.short_description = 'Description from email subject or body';
      incident.description = 'Full description from email body';
      var incidentSysID = incident.insert();
      gs.info('Incident created from email: ' + incidentSysID);
      } else {
      gs.error('Caller not found for email: ' + senderEmail);
      }
      Please hit helpful and accept my reply as helpful if it solve your problem.
      Thank you!

Anirudh Pathak
Mega Sage

Hi @shivaadapa ,

 

First you will need to fetch the caller from the email body. Use the below syntax - 

Fill in the field name with your field name coming from email body.

 

var caller = email.body.fieldName;

 

If caller is email sender then use this syntax to get caller -

var caller = email.origemail;

 

To Route ticket to "VIP Support Group" and set priority to 2, use below code -

 

var flag = false;
var user= new GlideRecord('sys_user');
user.addQuery('name',caller);
user.query();
if(user.next()){
if(user.vip == true) {
flag = true;
}
}

if(flag) {
current.assignment_group = 'VIP Support Group';
current.impact = '1';
current.urgency = '1';
current.insert();
}

 

Rajdeep Ganguly
Mega Guru

Sure, here are the steps to create an inbound email action and the script to fulfill your requirement:

1. Navigate to System Policy > Email > Inbound Actions in ServiceNow.
2. Click on New to create a new inbound action.
3. Fill in the necessary fields such as Name, Target table (Incident), and Conditions (if any).
4. In the Action script, you can use the following script:

javascript
(function runAction(email, email_action, incident) {
// Get the user record of the sender
var user = new GlideRecord('sys_user');
user.addQuery('email', email.from);
user.query();

if (user.next()) {
// If the user is a VIP, route the ticket to VIP Support Group and set priority as P2
if (user.vip == true) {
incident.assignment_group.setDisplayValue('VIP Support Group');
incident.priority = 2; // P2
}
}
})(email, email_action, current);


5. Save the inbound action.

This script will check if the sender of the email is a VIP user in the system. If they are, it will assign the incident to the "VIP Support Group" and set the priority to P2.

Please note that you need to replace 'VIP Support Group' with the exact name of the group in your instance. Also, the priority value may vary based on your instance's configuration.


nowKB.com

For asking ServiceNow-related questions try this :
For a better and more optimistic result, please visit this website. It uses a Chat Generative Pre-Trained Transformer ( GPT ) technology for solving ServiceNow-related issues.
Link - https://nowgpt.ai/

For the ServiceNow Certified System Administrator exams try this :
https://www.udemy.com/course/servicenow-csa-admin-certification-exam-2023/?couponCode=NOW-DEVELOPER

Community Alums
Not applicable

Hi,

Why all these complications, please do it very easily via Flow Designer.

Regards

Suman P.