email action fields

samadam
Mega Sage

I have email action, The email i receive has the field names with space in between them and the parsing is not working. IS there a way to parse this?

Requested Type
In-Person
Alternate Type
Virtual
Date Requested
2025-04-22
Time Requested
10:15 a.m.

2 REPLIES 2

Shree_G
Mega Sage

Hello @samadam ,

 

Spaces are rendered as underscores when a name : value pair gets parsed into a variable/value pair. E.g. "Requested Type" will get converted to Requested_Type. Inbound email script will create a variable as below :

email.body.Requested_Type

 

Try accessing the variables with spaces replacing with underscores.

 

Medi C
Giga Sage

Hello @samadam,

 

Could you please try the following:

var body = email.body_text; // Or email.body_html if you're parsing HTML
var lines = body.split('\n');

var data = {};
for (var i = 0; i < lines.length; i++) {
    var line = lines[i].trim();
    if (line === 'Requested Type') {
        data.requested_type = lines[i + 1].trim();
    } else if (line === 'Alternate Type') {
        data.alternate_type = lines[i + 1].trim();
    } else if (line === 'Date Requested') {
        data.date_requested = lines[i + 1].trim();
    } else if (line === 'Time Requested') {
        data.time_requested = lines[i + 1].trim();
    }
}

// Now use the data object to populate your record, Adjust as per your requirements
var gr = new GlideRecord('your_table');
gr.initialize();
gr.u_requested_type = data.requested_type;
gr.u_alternate_type = data.alternate_type;
gr.u_date_requested = data.date_requested;
gr.u_time_requested = data.time_requested;
gr.insert();