iNBOUND ACTION

Deepthi13
Tera Expert

hi

 
3 REPLIES 3

Tony Chatfield1
Kilo Patron

Hi, I think your issue is that splitting the body_text with '&' results in 5 rows/elements,
with the last one being empty this is because you are creating an additional element for each occurrence of '&'

var abc = email.body_text;
var rows = abc.split('&');
gs.info(rows.length);


A few options to resolve 
pop() the last element from the array.
Update your loop conditions to exclude the last element IE
 for (var i = 1; i < rows.length - 1; i++) 

 

You could also substring abc to remove the last '&'  before you split.

 abc = abc.substring(0, abc.lastIndexOf('&'));

 

 

Amit Gujarathi
Giga Sage
Giga Sage

HI @Deepthi13 ,
I trust you are doing great.
Please find the below corrected code for the same

(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

    for (var i = 1; i < rows.length; i++) { // Start loop from i = 1 to skip the header row
        if (rows[i].indexOf(disclaimer) !== -1) {
            gs.log("Skipping row containing disclaimer: " + rows[i]);
            continue; // Skip creating sc_task for this row
        }

        var row = rows[i].split('\t');
        var scTask = new GlideRecord('sc_task');
        scTask.initialize();
        var description = '';

        // Concatenate details from the row to form the description
        for (var j = 0; j < row.length; j++) {
            description += row[j] + ' '; // Adjust this to format details as needed
        }

        scTask.short_description = 'Task for Ercu';
        scTask.description = description.trim(); // Set the description field with row details
        scTask.insert();
        rowCount++;
    }
    gs.log("@@@ Total Rows Processed: " + rowCount);
})(current, event, email, logger, classifier);

Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi



Hi Amit,  @Amit Gujarathi  @Amit Gujarathi 
i am doing good, hope you are doing greate as well
The code u had given is correct, small more modification is required like in description i am getting output as 

_________________________________________________________________________________________

Application Id :
Title : 2
First Name : Ms
Surname : Abel
Internal/External : Tutor
NI Number : External
Start Date : 222
Pension Employer Contribution : 14-12-2023
Pension Employee Contribution : 1232
: 1234

___________________________________________________________________________________________

BUT DESIRED OUTPUT:
Application Id : 2

Title : Ms
First Name : Abel
Surname : Tutor
Internal/External : External
NI Number : 222
Start Date : 14-12-2023

Pension Employer Contribution : 1232
Pension Employee Contribution : 1234

______________________________
using code: 

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

    var emailBody = email.body_text;
    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
    var headerRow = rows[0].split('\n');
    for (var i = 1; i < rows.length; i++) {
        if (rows[i].indexOf(disclaimer) != -1) {
            continue;
        }
        var row = rows[i].split('\n');
        var scTask = new GlideRecord('sc_task');
        scTask.initialize();
        var description = '';
        var j = 0;
        var k = 0;
        while (j < headerRow.length) {
            description += headerRow[j] + ' : ' + row[j] + '\n';
            j++;
        }
        scTask.short_description = 'Task for Ercu';
        scTask.description = description.trim(); // Set the description field with row and header details
        scTask.insert();
        rowCount++;
    }

})(current, event, email, logger, classifier);
______________________________________________________________________________
sending below body in email 

 

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

&

 

 

 

 



 

please suggest