How to map data from email body to a field

yunus shadman
Tera Contributor

I wanted to map the data from email body to incident form , i have written an inbound action script to map the assignment group and configuration item . but i don't see any value in the newly created record . although the values i am providing via email is already present in the instance .

Inbound Action script:

(function runAction( /*GlideRecord*/ current, /*GlideRecord*/ event, /*EmailWrapper*/ email, /*ScopedEmailLogger*/ logger, /*EmailClassifier*/ classifier) {

    // Extract sender 's email address from the inbound email
  var customer = email.origemail;

  // Query the sys_user table to find the user with the sender's email address
  var userQuery = new GlideRecord('sys_user');
  userQuery.addQuery('email', customer);
  userQuery.query();

  // If a user with the sender's email address is found, set the caller_id field to the user's sys_id
  if (userQuery.next()) {
      current.caller_id = userQuery.getUniqueValue();
  } else {
      // If the user is not found, set the caller_id to a default value
      current.caller_id = 'be826bf03710200044e0bfc8bcbe5dfc';
  }
    current.assignment_group = email.body.assignment;
    current.cmdb_ci = email.body.configuration;
    // Add work notes about the email
    current.work_notes = "This email was sent by " + customer + "\n" + email.body_text;
    // Insert the incident record
    current.insert();

})(current, event, email, logger, classifier);
 
 
Email body:
Please create a task with the below details
assignment:Database
configuration:3D Groove Playback Engine

 

3 REPLIES 3

Weird
Mega Sage

You should be able to just check email.body.<your_field> for the values in the script. For example:

if(email.body.assignment != undefined){
   current.<field_name> = email.body.assignment;
}
if(email.body.configuration != undefined){
   current.<field_name> = email.body.configuration;
}


It's a good idea to add the if condition for each since there's a possibility that someone breaks the content and you might not want to print out undefined.

Sumanth16
Kilo Patron

Hi @yunus shadman ,

 

You can create a variable in the email body by using a field:value pair which you can then reference in your inbound action with email.body.field

 

eg:

put the field:value pair below in the email body and then the script in your inbound action and the assignment group will be set to Helpdesk.

Assignmentgroup: test

 

 

if(email.body.Assignmentgroup != undefined)
current.assignment_group.setDisplayValue('email.body.Assignmentgroup')

 

Add CI variable and use above syntax for CI

 

If I could help you with your Query then, please hit the Thumb Icon and mark it as Correct !!

 

Thanks & Regards,

Sumanth Meda

I tried in a same way , but still it is not working.