The CreatorCon Call for Content is officially open! Get started here.

Inbound email action - create ticket and update with Subject of email

maneesh3
Tera Contributor

Hi Team,

 

I have an requirement to create and update ticket with subject line instead of watermark. Client will send emails from JIRA system. They will have unique subject for each ticket sending to SNOW.

for example:

 

Subject: JIRA TKT NO 74 

 

So I need now to create ticket for the first email and next emails with same subject should be updated. Client did not have feasibility to send thread of emails , and everytime they send as new emails.

 

Please suggest code to do in inbound email actions

 

Help much appreciated. Thank you!

1 ACCEPTED SOLUTION

Hi @maneesh3,

 

If your subject is [JIRA] (C2SD-74) TEST  and you wants C2SD-74. then you can use the below regex to get the result

var jiraTicketNo = subjectStr.match(/\(([^)]+)\)/)[1].toString();

and comment out var regExSmit = /Task\d{6}/; line

 

Please mark the appropriate response as correct answer and helpful, This may help other community users to follow correct solution.
Thanks
Vijay Balotia

 

View solution in original post

16 REPLIES 16

Sandeep Rajput
Tera Patron
Tera Patron

@maneesh3 In your Inbound email action script, make following changes.

 

//	Note: current.opened_by is already set to the first UserID that matches the From: email address

var glideIncident = new GlideRecord('incident');
glideIncident.addEncodedQuery('short_description=' + email.subject);
glideIncident.query();
if (glideIncident.next()) {
    glideIncident.caller_id = gs.getUserID();
    glideIncident.comments = "received from: " + email.origemail + "\n\n" + email.body_text;
    glideIncident.short_description = email.subject;

    glideIncident.category = "inquiry";
    glideIncident.incident_state = IncidentState.NEW;
    glideIncident.notify = 2;
    glideIncident.contact_type = "email";

    if (email.body.assign != undefined)
        glideIncident.assigned_to = email.body.assign;

    if (email.importance != undefined) {
        if (email.importance.toLowerCase() == "high") {
            glideIncident.impact = 1;
            glideIncident.urgency = 1;
        }
    }
    glideIncident.update();
} else {
    current.caller_id = gs.getUserID();
    current.comments = "received from: " + email.origemail + "\n\n" + email.body_text;
    current.short_description = email.subject;

    current.category = "inquiry";
    current.incident_state = IncidentState.NEW;
    current.notify = 2;
    current.contact_type = "email";

    if (email.body.assign != undefined)
        current.assigned_to = email.body.assign;

    if (email.importance != undefined) {
        if (email.importance.toLowerCase() == "high") {
            current.impact = 1;
            current.urgency = 1;
        }
    }

    if (current.canCreate())
        current.insert();
}

Hope this helps.

Hi Sandeep,

 

Thanks a lot response. I have tried the script and it is creating new tickets 2nd time when same subject email is received:

maneesh3_0-1695196031810.png

 

I should be able to update ticket if received same subject, below is the part in inbound action I have implemented, please help if I am missing anything:

 

maneesh3_1-1695196101351.png

 

 

maneesh3_2-1695196142624.png

 

 

Thanks for the help here!