I need to add the reply email to the additional comments of the incident in inbound action

Muffin
Tera Contributor

I need to add the reply email to the additional comments of the incident in inbound action...The below code doesn't work...Please help

 

if (email.from.toLowerCase().indexOf("@xxxx.com") >= 0)
    {
        increply();
    }

if (email.from.toLowerCase().indexOf("@yyyy.com") >= 0)
    {
        increply();
    }

function increply(){
if (current.getTableName() == "incident") {
    var bodyText = email.body_text;
    if (!bodyText)
        bodyText = email.body_html;
    current.comments = "Reply from: " + email.origemail + "\n\n" + email.subject + "\n\n" + bodyText;
    current.update();
}
}

1 ACCEPTED SOLUTION

Sean35
Tera Contributor

you've declared bodyText here:  "var bodyText = email.body_text;"
then you've said, ~if I don't have bodyText here:  "if (!bodyText)"

because you did declare it then there will always be a bodyText so you will never run the code inside that If statement

View solution in original post

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

Is this inbound email action getting triggered?

Did you add log and check?

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

You may need to use .setJournalEntry() in your script. Try this: 

 

if (email.from.toLowerCase().indexOf("@xxxx.com") >= 0)
    {
        increply();
    }

if (email.from.toLowerCase().indexOf("@yyyy.com") >= 0)
    {
        increply();
    }

function increply(){
if (current.getTableName() == "incident") {
    var bodyText = email.body_text;
    if (!bodyText)
        bodyText = email.body_html;
    current.comments.setJournalEntry("Reply from: " + email.origemail + "\n\n" + email.subject + "\n\n" + bodyText);
    current.update();
}
}

 

For more about .setJournalEntry() see here.

Matt Taylor - G
Giga Guru

You may need to use .setJournalEntry() in your script. Try this: 

 

if (email.from.toLowerCase().indexOf("@xxxx.com") >= 0)
    {
        increply();
    }

if (email.from.toLowerCase().indexOf("@yyyy.com") >= 0)
    {
        increply();
    }

function increply(){
if (current.getTableName() == "incident") {
    var bodyText = email.body_text;
    if (!bodyText)
        bodyText = email.body_html;
    current.comments.setJournalEntry("Reply from: " + email.origemail + "\n\n" + email.subject + "\n\n" + bodyText);
    current.update();
}
}

 

For more about .setJournalEntry() see here.

 

Sean35
Tera Contributor

you've declared bodyText here:  "var bodyText = email.body_text;"
then you've said, ~if I don't have bodyText here:  "if (!bodyText)"

because you did declare it then there will always be a bodyText so you will never run the code inside that If statement