email with excel content in emailbody to create a sctask.

Jyo090
Tera Contributor

Hello All,

 

I am using below format to create a multiple SC task based on the input we receive from external source as excel via email. My requirement is to we don't want to create extra dummy column like "ZZZ" . we only want to proceed with provided columns. Can you please suggest us any changes in the script without ZZZ column.

 

requirement is based on each row data, it have to create a 1 sc task.

 

example :  In the below format, data should copy to description of SCTASK.

First Name:Minesh
Last Name:Morjaria

 

 

(function runAction( /* GlideRecord */ current, /* GlideRecord */ event, /* EmailWrapper */ email, /* ScopedEmailLogger */ logger, /* EmailClassifier */ classifier) {
    var emailBody = email.body_text;
    var rows = emailBody.split('zzz');
    var disclaimer = "This email is sent on behalf of company"; // 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 = '';
       
        }
        scTask.short_description = 'Task for dd';
        scTask.description = description.trim(); // Set the description field with row and header details      
        scTask.assignment_group="628fc212979f5d5005fcb00de053afb1";
        try {
            scTask.insert();
        } catch (e) {
            gs.error('Error creating sc_task record: ' + e);
        }
    }
})(current, event, email, logger, classifier);

excel format:
 
 
 
 

 Application_Id

MIXII email address

Email

First Name

Last Name

Employee ID

Please re-confirm your country of residence

Reimbursement Currency

Company (Legal Entity)

Costing Value

Line Manager Name & Employee ID

Hiring Manager Email

Will this employee need to approve expenses?

Will this employee need to claim expenses within the next 3 months?

 
 
ZZZ

54545

Minesh.lalaa@POX.com

baka.lalala@hotmail.com

Minesh

Morjaria

801241

United Kingdom

GBP

MIXII Group PLC

dfsfsdsdsd

John cerry (390362)

john.terry@xo.com

No

Yes

ZZZ
 

509565

Aimee.butcher@POX.com

agahfdfd@hotmail.com

Aimee

Fletcher

345334

United states

GBP

MIXII Security Limited

sdsfsfsfds

Brett Oough (34343)

brett.c@pox.com

Yes

Yes

ZZZ
 
1 REPLY 1

maroon_byte
Mega Sage

If your data is in a table within the email body then its in HTML format. You can see the HTML code when you see the email in plain text (body text in sys_email). You will have to first remove the HTML tags and then process data. See if below helps:

 

https://www.servicenow.com/community/itom-forum/inbound-email-action-extract-data-from-an-html-table...

 

Regards,

Sharad