Inbound email action issue

mohanambalnanja
Tera Contributor

Hi,

 

I have created an inbound action to create "incident" whenever email is received from specific email ID and subject.

While testing, I have sent an email from my email ID with specific subject. Incident is created when I sent an email from my email ID. But it didn't create the incident when the email is from that specific email ID. Email ID is present in ServiceNow.

Below is my script. 

 

var callerEmailAddress = email.body.caller;             //Set Caller Details
    var user = new GlideRecord('sys_user');
    user.addQuery('email', callerEmailAddress);
    user.query();

 

    if (user.next())
    {
        current.caller_id = user.sys_id;
    }

    var configurationItemName = email.body.dashboard_name; // Set Configuration Item
    var configurationItem = new GlideRecord('cmdb_ci');
    configurationItem.addQuery('name', configurationItemName);
    configurationItem.query();

    if (configurationItem.next())
    {
        current.setValue("cmdb_ci", configurationItem.sys_id);
    }

    var businessServiceName = email.body.business_service; // Set Business Service
    var businessService = new GlideRecord('cmdb_ci_service');
    businessService.addQuery('name', businessServiceName);
    businessService.addQuery('u_active', true);
    businessService.query();

    if (businessService.next())
    {
        current.setValue("u_business_service", businessService.sys_id);
    }

    var group = email.body.assignment_group;                // Set Assignment Group
    var GROUP_TYPE_ASSIGNABLE = "463cd4901b38e510c900a6c7b04bcbeb";
    var userGroup = new GlideRecord('sys_user_group');
    userGroup.addQuery("type", "LIKE", GROUP_TYPE_ASSIGNABLE);
    userGroup.addQuery("name", group);
    userGroup.query();

    if (userGroup.next())
    {
        current.setValue("assignment_group", userGroup.sys_id);
    }

    var workNotes = '\nWork Notes: '+email.body.work_notes;  //Update work notes
    var owner = '\nOwner: ' + email.body.owner;            
    var developerEmailID = '\nDevelopers Email Ids: ' + email.body.developers_email_ids;
    var requestedEmailID = '\nRequested Email Ids: ' + email.body.requested_email_ids;
    var dashboardURL = '\nDashboard URL: ' + email.body.dashboard_url;
    var region = '\nRegion: ' + email.body.region;
    var country = '\nCountry: ' + email.body.country;
    var brachName = '\nBranch Name: ' + email.body.branch_name;

    current.work_notes = workNotes+owner + developerEmailID + requestedEmailID + dashboardURL + region + country + brachName;
    current.insert();
}
 
11 REPLIES 11

which field mapping is missed can you share...?


☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....

LinkedIn - Lets Connect

mohanambalnanja
Tera Contributor

Below are the field details.

 

Caller, Assignment Group, Configuration Item, Business service and work notes. 

 

mohanambalnanja_0-1713169302905.png

 

mohanambalnanja
Tera Contributor

This is the email which we receive for inbound action.

 

mohanambalnanja_1-1713170747338.png

From the email body, I am taking the details and passing it in incident form. 

Hi @mohanambalnanja 

 

This should work-

 

var assignmentGroup = new GlideRecord('sys_user_group');
assignmentGroup.addQuery('name', assignmentGroup);
assignmentGroup.query();
if (assignmentGroup.next()) {
    current.assignment_group = assignmentGroup.sys_id;
}

if (workNotes) {
    current.work_notes = 'Work Notes: ' + workNotes;
}

 

You can make changes for other fields as well.

 

Regards,

Amit

No. It didn't  work. Thanks for the update.