Need help in inbound email action

nameisnani
Giga Sage

Hi Team 

 

can any one please help me on this below requirement 

 

For ' Request Help ' catalog item 

 

- If a request is coming from an email : 

   --- User from Email address that is being sent from .

- if a user is not identified user requested for 

- if a user is still not identified set Opend by field ' Person not in database ' 

 

How to configure this required . 

 

can any one please help me steps 

 

Note - Email subject should contains ' EpicCare Link ' 

 

Request should created along with ritm 

 

9 REPLIES 9

Tanushree Maiti
Tera Patron

Hi @nameisnani 

 

Try this:

//Replace Sys_id as required.

Inbound Email Action Script

  • Navigate to System Policy > Email > Inbound Actions and
  • create a new record for the sc_req_item table.

 

var senderEmail = email.from;

var userGr = new GlideRecord('sys_user');

userGr.addQuery('email', senderEmail);

userGr.query();

 

var cartId = GlideGuid.generate(null);

var cart = new Cart(cartId);

var item = cart.addItem('SYS_ID_OF_REQUEST_HELP_CATALOG_ITEM'); // Replace with your Catalog Item's sys_id

 

if (userGr.next()) {

    cart.setVariable(item, 'requested_for', userGr.sys_id);

    cart.setVariable(item, 'opened_by', userGr.sys_id);

} else {

    cart.setVariable(item, 'opened_by', 'SYS_ID_OF_PERSON_NOT_IN_DATABASE_RECORD');

}

 

var rc = cart.placeOrder();

Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti

@Tanushree Maiti  your script tested - In requestor for field ' Person in not data base ' is coming but in opened by is still empty .

 

what should i do now 

Hi @nameisnani 

 

Share your script. Ensure the sys_id - you replaced present in sys_user table.

 

Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti

Hi @Tanushree Maiti 

 

Current Inbound script 

var senderUser = null;
var gr = new GlideRecord('sys_user');
gr.addQuery('email', email.origemail);
gr.query();
if (gr.next()) {
    senderUser = gr.sys_id.toString();
}

// Fallback function: find "Person not in Database" user
var senderEmail = email.from;

var userGr = new GlideRecord('sys_user');

userGr.addQuery('email', senderEmail);

userGr.query();



var cartId = GlideGuid.generate(null);

var cart = new Cart(cartId);

var item = cart.addItem('46a1e017ffe166502cdaf8b67c4fd979'); // Replace with your Catalog Item's sys_id



if (userGr.next()) {

    cart.setVariable(item, 'requested_for', userGr.sys_id);

    cart.setVariable(item, 'opened_by', userGr.sys_id);

} else {

    cart.setVariable(item, 'opened_by', '5136503cc611227c0183e96598c4f706');

}



var rc = cart.placeOrder();

 

Flow 

nameisnani_0-1784518469426.png

 

Action 2 - updated Request record script 

 

 

/*
**Access Flow/Action data using the fd_data object. Script must return a value. 
**Order number is offset by +1 in Error Handling Section.
**Available options display upon pressing "." after fd_data
**example: var shortDesc = fd_data.trigger.current.short_description;
**return shortDesc;
*/
var requestedFor = fd_data["1_get_catalog_variables"].requested_for;
var loggedInUser = fd_data.trigger.current.sys_created_by;

function getPersonNotInDatabase() {
    var gr = new GlideRecord('sys_user');
    gr.addQuery('first_name', 'Person not in');
    gr.addQuery('last_name', 'Database');
    gr.query();
    if (gr.next()) {
        return gr.sys_id.toString();
    }
    return null;
}

if (loggedInUser) {
    return loggedInUser;
}

if (requestedFor) {
    return requestedFor;
}

return getPersonNotInDatabase();

 

Update ritm record script 

 

/*
**Access Flow/Action data using the fd_data object. Script must return a value. 
**Order number is offset by +1 in Error Handling Section.
**Available options display upon pressing "." after fd_data
**example: var shortDesc = fd_data.trigger.current.short_description;
**return shortDesc;
*/
var email_subject = fd_data.trigger.request_item.variables.email_subject;
if(email_subject != '') {
    return fd_data.trigger.request_item.variables.requested_for;;
} else {
    return '';
}

 

 

Before insert and update BR 

 

Current Business Rule:
-----------------------------
(function executeRule(current, previous) {

    var FALLBACK_USER_SYS_ID = "5136503cc611227c0183e96598c4f706";

    if (current.request.requested_for == FALLBACK_USER_SYS_ID) {

        current.opened_by = FALLBACK_USER_SYS_ID;

        var reqGr = new GlideRecord("sc_request");
        if (reqGr.get(current.request)) {
            reqGr.opened_by = FALLBACK_USER_SYS_ID;
            reqGr.update();
        }
    }

})(current, previous);

 

 

 

Test cases we have tested 

1 . Sent email from personal emai - Worked Fine [ Both opened by and requested for populated with person not in database ] 

1. Already user there in data base - sent email from outlook [ Only Requestor for was updated with user name - opened by field is empty ] 

 

@Tanushree Maiti  can u please help what was the wrong in configuration - where exactaly neeed to fx 

 

@Ankur Bawiskar  Need your help