reply emails shall be copied to associated child cases and incidents.

kalakaramad_20
Tera Contributor

I have a requirement that when the client replies to some cases from the email method the reply email must be copied to associated incident.

kalakaramad_20_0-1707910326595.png

The same content email received must be copied to the incident also. Can anyone help ?
Thanks in advance.

21 REPLIES 21

Mark Manders
Mega Patron

Are you using inbound actions, or inbound email flows? 
You can just script or configure your flow to get your related records and update the email body to the work notes of those tasks. You can't associate the same email to multiple records, but you can just copy the content from the inbound email.


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

Amit Pandey
Kilo Sage

Hi @kalakaramad_20 

 

I don't think you can attach the emails to associated records. You can copy the email content to the comments in associated incidents. Pls check and make changes in the following inbound action-

(function runMailScript(email, template, table, record) {

    var inc = parseIncidentNumber(email.body);
    var emailBody = email.body_text; // Assuming plain text email

    var incGR = new GlideRecord('incident');
    if (incGR.get('number', inc)) {
      
        incGR.comments = "Client reply:\n" + emailBody;
        incGR.update();

        sendEmailToIncident(incGR.sys_id, emailBody);
    }

})(email, template, table, record);

function parseIncidentNumber(emailBody) {
    // Logic to parse incident number from email body
    // Return incident number
}

function sendEmailToIncident(incidentSysId, emailBody) {
    // Logic to send email copy to associated incident
}

Regards,

Amit

This shall be done on inbound actions ?

var case_state = current.state;

if (current.state == 500) {
 
    var lines = email.body_text.split('\n');
    var firstword = "";

    if (lines.length > 0)
        firstword = lines[0].replace(/^\s+|\s+$/g,'');
   
    firstline = firstword.toLowerCase();
   
    if (firstline) {
        if(firstline.indexOf("reject") == 0)
            current.state = 2; // Set the state to 10 (assuming this means "rejected")
        else if(firstline.indexOf("accept") == 0)
            current.state = 6;  
    }
}
if (current.getTableName() == 'sn_customerservice_case') {
        current.comments = current.comments = "reply from: " + email.origemail + "\n\n" + email.body_text;

    }


else if (current.u_on_hold_reason_1 == 1) {
    current.state = 2;
}
else if (current.state == 200) {
    current.state = 2;
}

else {
    current.sys_updated_on = "";
}

current.update();
What to add into this inbound action.