We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

How to convert template data into inbound action for creation incident

Kat123
Tera Contributor

Kat123_0-1755244954917.png

 

I will get above template from user in email

what script we will use for converting this data into incident 

7 REPLIES 7

Bhuvan
Giga Patron

Kat123
Tera Contributor

like i will use normal script for getting project value -

if (email.body.projectt != undefined) {
current.u_project = email.body.project;
}

 so i will receive data through email in html format (in table format, like rows and columns)

so how i can convert tabular data or table format data into incident via inbound action.

what changes in script needed

Raghu Ram Y
Kilo Sage

@Kat123 Please try the below script. For this sample, I mapped Title to Short Description and Project to Description. You can replace them with the relevant fields as needed.

    var htmlBody = email.body_html;
    var parser = new GlideXMLUtil();
    var doc = parser.parse(htmlBody);

    var title = "";
    var project = "";

    var rows = doc.getElementsByTagName("tr");

    for (var i = 0; i < rows.getLength(); i++) {
        var cells = rows.item(i).getElementsByTagName("td");
        if (cells.getLength() >= 2) {
            var label = cells.item(0).getTextContent().trim().toLowerCase();
            var value = cells.item(1).getTextContent().trim();

            if (label.indexOf("title") > -1) {
                title = value;
            }
            if (label.indexOf("project") > -1) {
                project = value;
            }
        }
    }

    var inc = new GlideRecord("incident");
    inc.initialize();
    inc.short_description = title || "No Title Provided";
    inc.description = project || "No Project Provided";
    inc.insert();

  

not creating incident 

getting 'Incident Creation : did not create or update incident using current ' in email log