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

@Vijay Balotia1 

 

Please suggest on above issue. Is there any wrong which I have included in code.

 

Thank you!

Hi @maneesh3,

 

Sorry for delay in response. please use this code for sure it will work.

 

 

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


    //var subjectStr = "JIRA TKT NO Task7434234 ";
    var subjectStr = email.subject;
    var regExSmit = /Task\d{6}/; //you can adjust this based on your subject.
    var jiraTicketNo = subjectStr.match(regExSmit).toString();
    var gr = new GlideRecord("sn_customerservice_case");
    gr.addQuery("correlation_id", jiraTicketNo);
    gr.query();
    if (gr.next()) {
        gr.worknotes = email.body_text;
        //similarly you can add more fields that you want to add.
        gr.update();
    } else {
        gr.correlation_id = jiraTicketNo;
        gr.short_decription = email.subject;
        //similarly you can add more fields that you want to add.
        gr.insert();
    }
    // Implement email action here

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

 

 

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

Hi Vijay,

 

Perfect its working now. Last help for Subject line like below what should regex :

 

[JIRA] (C2SD-74) TEST -- ABC  --->  I should take only C2SD-74 

 

Also is there any document or reference I can play with subject lines.

 

Thanks 

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

 

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @maneesh3 

 

Greetings!!

 

Here is link to understand / solve your problem:

 

https://docs.servicenow.com/en-US/bundle/vancouver-platform-administration/page/administer/notificat...

 

AtulyaG_1-1694787872093.png

 

 

 

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************