How to create incident and assigned that incident to user mention in mail body

RushiM
Tera Contributor

Hello Community,

I want a functionality that create an incident on received an email, based on that mail incident should create and prepopulate following fields, 

subject -> short description

Mail body -> description

category -> Security (not from mail)

subcategory -> Quarantine (not from mail)
Assigned to -> Email of user mention in mail after 'user:' .  ex.user:abc.xyz@example.com
so the incident assigned to Abc Xyz user.

As now I am scripting for incident is generating but Assigned to, category, subcategory is not populate.

Even the log is not displays for userName or email.

 

I will very greateful on our help,

Thanks in advance.

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

        var userEmail = email.body_text.user;
        gs.log("Email is " + userEmail);

        var useremail = email.body_text.user.toString();
        gs.log("email:" + useremail);
        emailParsed = emailParsed.split(' ');
        gs.info('SN Community test [email]: ' + emailParsed);
        var grUser = new GlideRecord('sys_user');
        grUser.addQuery('email', useremail);
        grUser.addQuery('email', emailParsed[0]);
        grUser._query();

        if (grUser._next()) {
            gs.info('SN Community test [IF]: ok');
            var assigned_to = grUser.getValue('caller');
            gs.log(useremail);
            var grChange = new GlideRecord('incident');
            grChange.newRecord();
            grChange.setValue('assigned_to', grUser.getUniqueValue());
            grChange.insert();
        }

})(current, event, email, logger, classifier);


 

1 REPLY 1

Mark Manders
Mega Patron

Can you share the incoming email as well? If the log doesn't give you that email address, it's just not recognized.

I am also missing some background in the logic of your script: you are creating a variable 'assigned_to' from the caller (which isn't a field on the email form) and you don't do anything with it? You are defining userEmail twice? 


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark