Inbound action data

Deepthi13
Tera Expert

Hi Team, 

I am trying to set the data from inbound action in to description and (name-value pair) field with the data sent from in the excel. but description and name-value pair key both are not working properly. please suggest 
Script:

(function runAction( /*GlideRecord*/ current, /*GlideRecord*/ event, /*EmailWrapper*/ email, /*ScopedEmailLogger*/ logger, /*EmailClassifier*/ classifier) {
    var emailBody = email.body_text;
    gs.log("@@@1 Raw Email Body: " + emailBody);
    var rows = emailBody.split('&');
    var rowCount = 0;
    var disclaimer = "The contents of this e-mail and any attachment(s) may contain confidential or privileged information for the intended recipient(s)."; // Adjust this to match the start of your disclaimer text
    // Extract header row
    var headerRow = rows[0].split('\t');
    for (var i = 1; i < rows.length; i++) { // Start loop from i = 1 to skip the header row
        if (rows[i].indexOf(disclaimer) !== -1) {
            // Skip rows containing disclaimer text
            gs.log("Skipping row containing disclaimer: " + rows[i]);
            continue;
        }
        var row = rows[i].split('\t');
        var scTask = new GlideRecord('sc_task');
        scTask.initialize();
        var uDataString = ''; // String to store name-value pairs for u_data field
        var description = ''; // String to store description details for the task
        // Construct the description by pairing each header name with its corresponding value in the row
        for (var j = 0; j < headerRow.length; j++) {
            var headerName = headerRow[j];
            var value = row[j];
            // Format: HeaderName : Value on a new line
            uDataString += headerName + ' : ' + value + '\n';
            description += headerName + ' : ' + value + '\n';
        }
scTask.short_description = 'Task for Ercu';
        scTask.u_data = uDataString.trim(); // Set the u_data field with the name-value pairs as a string
        scTask.description = description.trim(); // Set the description field with row and header details
        scTask.insert();
        rowCount++;
    }
    gs.log("@@@ Total Rows Processed: " + rowCount);
})(current, event, email, logger, classifier);

The email excel format i am sending:

 

Application Id

Title

First Name

Surname

Internal/External

NI Number

Start Date

Pension Employer Contribution

Pension Employee Contribution

&

1

Mr

Sam

Ham

Internal

1023

11-11-2023

2232

2223

&

2

Ms

Abel

Tutor

External

222

14-12-2023

1232

1234

&

3

Mr

Ryan

Kelly

External

231

15-01-2023

2314

1221

&

 

7 REPLIES 7

(function runAction(/* GlideRecord */ current, /* GlideRecord */ event, /* EmailWrapper */ email, /* ScopedEmailLogger */ logger, /* EmailClassifier */ classifier) {
    var emailBody = email.body_text;
    var rows = emailBody.split('\t');
    var disclaimer = "The contents of this e-mail and any attachment(s) may contain confidential or privileged information for the intended recipient(s)."; // Adjust this to match the start of your disclaimer text
    var headerRow = rows[0].split('\&'); // Split by tab character assuming columns are separated by tabs
    for (var i = 1; i < rows.length; i++) {
        if (rows[i].indexOf(disclaimer) != -1) {
            continue;
        }
        var row = rows[i].split('\n'); // Split by tab character for each row to get column values
        var scTask = new GlideRecord('sc_task');
        scTask.initialize();
        var description = '';      
        for (var j = 0; j < 9 ; j++) {//while(j< (headerRow.length-1)){
            description += headerRow[j].trim() + ' : ' + row[j+1] + '\n'; // Format: HeaderName : Value
            if(j==2){
                scTask.u_firstname=row[j];
                gs.log("&&& "+row[j]);
            }
        //j++;
        }      
        scTask.short_description = 'Task for Ercu';
        scTask.description = description.trim(); // Set the description field with row and header details      
       
        try {
            scTask.insert();
        } catch (e) {
            gs.error('Error creating sc_task record: ' + e);
        }
    }
})(current, event, email, logger, classifier);

(function runAction(/* GlideRecord */ current, /* GlideRecord */ event, /* EmailWrapper */ email, /* ScopedEmailLogger */ logger, /* EmailClassifier */ classifier) {
    var emailBody = email.body_text;
    var rows = emailBody.split('\&');
    var disclaimer = "The contents of this e-mail and any attachment(s) may contain confidential or privileged information for the intended recipient(s)."; // Adjust this to match the start of your disclaimer text
    var headerRow = rows[0].split('\n'); // Split by tab character assuming columns are separated by tabs
    for (var i = 1; i < rows.length; i++) {
        if (rows[i].indexOf(disclaimer) != -1) {
            continue;
        }
        var row = rows[i].split('\n'); // Split by tab character for each row to get column values
        var scTask = new GlideRecord('sc_task');
        scTask.initialize();
        var description = '';      
        for (var j = 0; j < 9 ; j++) {//while(j< (headerRow.length-1)){
            description += headerRow[j].trim() + ' : ' + row[j+1] + '\n'; // Format: HeaderName : Value
            if(j==2){
                scTask.u_firstname=row[j];
                gs.log("&&& "+row[j]);
            }
        //j++;
        }      
        scTask.short_description = 'Task for Ercu';
        scTask.description = description.trim(); // Set the description field with row and header details      
       
        try {
            scTask.insert();
        } catch (e) {
            gs.error('Error creating sc_task record: ' + e);
        }
    }
})(current, event, email, logger, classifier);
 
 
 

(function runAction(/* GlideRecord */ current, /* GlideRecord */ event, /* EmailWrapper */ email, /* ScopedEmailLogger */ logger, /* EmailClassifier */ classifier) {
    var emailBody = email.body_text;
    var rows = emailBody.split('\&');
    var disclaimer = "The contents of this e-mail and any attachment(s) may contain confidential or privileged information for the intended recipient(s)."; // Adjust this to match the start of your disclaimer text
    var headerRow = rows[0].split('\n'); // Split by tab character assuming columns are separated by tabs
    for (var i = 1; i < rows.length; i++) {
        if (rows[i].indexOf(disclaimer) != -1) {
            continue;
        }
        var row = rows[i].split('\n'); // Split by tab character for each row to get column values
        var scTask = new GlideRecord('sc_task');
        scTask.initialize();
        var description = '';      
        for (var j = 0; j < 9 ; j++) {//while(j< (headerRow.length-1)){
            description += headerRow[j].trim() + ' : ' + row[j+1] + '\n'; // Format: HeaderName : Value
            if(j==2){
                scTask.u_firstname=row[j];
                gs.log("&&& "+row[j]);
            }
        //j++;
        }      
        scTask.short_description = 'Task for Ercu';
        scTask.description = description.trim(); // Set the description field with row and header details      
       
        try {
            scTask.insert();
        } catch (e) {
            gs.error('Error creating sc_task record: ' + e);
        }
    }
})(current, event, email, logger, classifier);