Would I be able to pull the user_name from an email body? How would I be able script that?

Wyatt Fudal1
Tera Guru

I have created a flow that generates an incident from email. The email that triggers the flow is from a generic service account in our environment but in the email body, the user's email will be populated. In theory, I should be able to pull the user_name from that. How would I script that? This process is in flow designer.  

1 ACCEPTED SOLUTION

Prithvi_b
Tera Guru

Hi @Wyatt Fudal1 ,

 

In a normal Inbound email action , we can get the email id using redux to the email body in  action part, where we can script. Using this ,we can save it a variable and initilaize an incident.

But in a flow, I think we have to create flow  action, where we get the output as email id. Then we can use it in the flow designer. Adding the code for getting sysid of the user to create incident.

(function execute(inputs, outputs) {
// ... code ...
  var shortDesc=inputs['EmailBody'];
   function extractEmails ( shortDesc ){
            return shortDesc.match(/([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9_-]+)/gi);
   }
 var user_email_id = extractEmails( shortDesc );
  
  var userid=new GlideRecord ('sys_user');
  userid.addQuery('email',user_email_id);
  userid.query();
  if(userid.next()){
   var id =userid.getUniqueValue();
    
  }
  outputs ['id']=id; //you can get email id of user using this by using user_email_id as output
})(inputs, outputs);

Please verify this. Will add some screenshots .Please try.

 

Thankyou, 

prithvi

View solution in original post

2 REPLIES 2

Prithvi_b
Tera Guru

Hi @Wyatt Fudal1 ,

 

In a normal Inbound email action , we can get the email id using redux to the email body in  action part, where we can script. Using this ,we can save it a variable and initilaize an incident.

But in a flow, I think we have to create flow  action, where we get the output as email id. Then we can use it in the flow designer. Adding the code for getting sysid of the user to create incident.

(function execute(inputs, outputs) {
// ... code ...
  var shortDesc=inputs['EmailBody'];
   function extractEmails ( shortDesc ){
            return shortDesc.match(/([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9_-]+)/gi);
   }
 var user_email_id = extractEmails( shortDesc );
  
  var userid=new GlideRecord ('sys_user');
  userid.addQuery('email',user_email_id);
  userid.query();
  if(userid.next()){
   var id =userid.getUniqueValue();
    
  }
  outputs ['id']=id; //you can get email id of user using this by using user_email_id as output
})(inputs, outputs);

Please verify this. Will add some screenshots .Please try.

 

Thankyou, 

prithvi

Wyatt Fudal1
Tera Guru

 Thank you that worked.