Inbound Email Action Query

Anusha Medharam
Tera Contributor

when i sent email to servicenow based on that email one case will be created in servicenow . In the mail i give short description and con figuration Item . that information is set in short description and configuration Item in case Form. How to write Inbound Email Action in servicenow case is create based on prefix in subject that subject is ' Case'.. Configuration Item is Reference field in Case Form.

 

 

1 REPLY 1

Ratnakar7
Mega Sage
Mega Sage

Hi @Anusha Medharam ,

 

There's an out of the box Inbound Email Action "Create Case via property" present to create Case from incoming email with all the fields, after validating that To address is mentioned in the property glide.cs.email.case_queue_address.
But, in your case you need to create a case based on prefix, so it would be better to clone this inbound action by using Insert & Stay functionality and then adding a script after the existing one.

Note: Set the order of execution of new inbound action less than the OOTB one.

You can also, refer below sample code for inbound action :

(function runMailScript(email, template, email_action, email_table, email_record) {

    // Check if the email subject starts with "Case"
    if (email.subject.startsWith('Case')) {

        // Create a new case record
        var newCase = new GlideRecord('sn_customerservice_case');
        newCase.initialize();
        
        // Set short description from the email body
        newCase.short_description = email.body_text;

        // Set configuration item (replace 'YOUR_CI_NAME' with the actual configuration item name)
        newCase.configuration_item = 'YOUR_CI_NAME';

        // Set other fields as needed

        // Insert the new case record
        var caseSysID = newCase.insert();
        
        // Log the created case sys_id
        gs.info('New Case Created: ' + caseSysID);

        // Stop further processing of the email
        return;

    }

})(email, template, email_action, email_table, email_record);

 

Thanks,

Ratnakar