inbound

Jyo090
Tera Contributor
 
2 REPLIES 2

Kartik Magadum
Kilo Sage

Hello @Jyo090 

Please try below code.

 

(function runAction( /* GlideRecord */ current, /* GlideRecord */ event, /* EmailWrapper */ email, /* ScopedEmailLogger */ logger, /* EmailClassifier */ classifier) {
    var emailBody = email.body_text;
    var disclaimer = "This email is sent on behalf of xxxxx Group plc";
    var rows = emailBody.split('\n'); // Split the email body into lines

    var headerRow = rows[0].split('\t'); // Assuming tab-separated columns in the header row

    for (var i = 1; i < rows.length; i++) {
        if (rows[i].indexOf(disclaimer) != -1) {
            continue;
        }

        var rowValues = rows[i].split('\t'); // Assuming tab-separated columns in each row

        if (rowValues.length !== headerRow.length) {
            // Skip rows that do not have the same number of columns as the header
            continue;
        }

        var scTask = new GlideRecord('sc_task');
        scTask.initialize();
        var description = '';

        for (var j = 0; j < headerRow.length; j++) {
            description += headerRow[j] + ':' + rowValues[j] + '\n';
            
            // Assuming you want to set a specific field based on a condition, e.g., j == 1
            if (j == 1) {
                scTask.u_arcu_application_id = rowValues[j];
            }
        }

        scTask.short_description = 'Task for Ercu';
        scTask.description = description.trim();
        scTask.assignment_group = "628fc212979f5d5005fcb00de053afb1";

        try {
            scTask.insert();
        } catch (e) {
            gs.error('Error creating sc_task record: ' + e);
        }
    }
})(current, event, email, logger, classifier);

 

Thanks

Kartik Magadum

-O-
Kilo Patron
Kilo Patron

Without submitting a sample e-mail it is not possible to say whether what you have above is good or not.