Create a Request Item using data passed in Inbound Email in ServiceNow

Community Alums
Not applicable

Hi There,

 

I have a requirement to create a request item when the below data is passed to ServiceNow's mail ID using Inbound Email Action. Below is the fixed format ServiceNow will be receiving, want to understand how to parse the data in :

 

Region: AMER

Country: Canada (Reference field)

Company: Test Canada Inc. (Reference field)

City: Montreal (Reference field)

Department: Information Technology (IT) (Reference field)

SF ID: 123000

Employee ID: 123000

Cost Center: 000123

Job Title: 

Personal Title: 

First Name: Test Onboarding

Legal Name: 

Last Name: ServiceNow

Date of Joining: 2024-06-15

Line Manager: Tejas Test

Line Manager Email: tejas.test@test.com

Ticket URL: 

Ticket ID: SR-114283

 

Thanks,

Tejas

16 REPLIES 16

Community Alums
Not applicable

Hi @Hemanth M1,

 

In inbound email action I tried putting log comments with below scripts, It's creating request that I can see in logs but now issue is in the email we send to ServiceNow, in the email logs the "Target" still shows Incident. So, it's creating request as well as Incident, not sure what's happening, I checked other inbound email actions through Incident getting created I don't see any conflict in the configuration. Unable to point out issue

 

Inbound email action script:
(function runAction( /*GlideRecord*/ current, /*GlideRecord*/ event, /*EmailWrapper*/ email, /*ScopedEmailLogger*/ logger, /*EmailClassifier*/ classifier) {

    createRequest();

    function createRequest() {
        gs.log("Hey, I am in createRequest() function");

        var mgr = ''; // You can use this line to set a default
        var ctry = '';
        var cmny = '';
        var city = '';
        var dept = '';

        var gr = new GlideRecord('sys_user');
        if (gr.get('name', email.body.manager_name)) {
            mgr = gr.sys_id;
        }
        var gr1 = new GlideRecord('core_country');
        if (gr1.get('name', email.body.country)) {
            ctry = gr1.sys_id;
        }
        var gr2 = new GlideRecord('core_company');
        if (gr2.get('name', email.body.company)) {
            cmny = gr2.sys_id;
        }
        var gr3 = new GlideRecord('u_city');
        if (gr3.get('u_city', email.body.city)) {
            city = gr3.sys_id;
        }
        var gr4 = new GlideRecord('cmn_department');
        if (gr4.get('name', email.body.department)) {
            dept = gr4.sys_id;
        }
        gs.log("Hey, Tejas, now I am going to create request :");
        var cartId = GlideGuid.generate(null);
        var cart = new Cart(cartId);
        // add in cart, substitute your cat item sys_id
        var item = cart.addItem('b106bc193bce4610ea3a202a85e45aeb');
        // set requested for, substitute your requested for
        //Set Variables in your Cart Item
        cart.setVariable(item, 'select_the_account', 'Internal');
        cart.setVariable(item, 'region', email.body.region);
        cart.setVariable(item, 'country', ctry);
        cart.setVariable(item, 'company', cmny);
        cart.setVariable(item, 'city', city);
        cart.setVariable(item, 'department', dept);
        cart.setVariable(item, 'line_manager', mgr); // Note the change here
        cart.setVariable(item, 'successfactor_id', email.body.sf_id);
        cart.setVariable(item, 'employee_number', email.body.employee_id);
        cart.setVariable(item, 'job_title', email.body.job_title);
        cart.setVariable(item, 'personal_title', email.body.personal_title);
        cart.setVariable(item, 'first_name', email.body.first_name);
        cart.setVariable(item, 'last_name', email.body.last_name);
        cart.setVariable(item, 'legal_name', email.body.legal_name);
        cart.setVariable(item, 'date_of_joining', email.body.date_of_joining);
        //cart.setVariable(item, 'line_manager_email', email.body.line_manager_email);
        var cartmsg = "received from: " + email.origemail + "\n\n" + email.body_text;
        cart.setVariable(item, 'comments', cartmsg);
        var rc = cart.placeOrder();
        gs.log("Hey, Tejas, request number is :"+rc.number);
    }
    current = rc.sys_id;
})(current, event, email, logger, classifier);
 
Tejas12_0-1718247646390.pngTejas12_1-1718247693784.png

 

Hi @Community Alums ,

 

1)Change the order to may be 10 and check stop processing check box and verify 

2) Check if any inbound flows are configured (inbound flows would run before inbound actions)

 

 

Accept and hit Helpful if it helps.

Thank you,
Hemanth
Certified Technical Architect (CTA), ServiceNow MVP 2024, 2025