Submit and close a catalog item request from inbound email

Alex Saager1
Tera Contributor

Hi there,

 

I would like to submit and automatically close a catalog item request from an inbound email.

 

The catalog item is very basic and only has one variable (description - multi-line text variable) and only visible for one team, the idea behind this is just logging a ticket for audit purposes.

 

What would be the best way to do this? I had a look at flow designer but could not see anyway to close the ticket all in one go, or would this be better done using an inbound email action and scripting?

 

Any help or guidance would be appreciated?

Many thanks,

Alex

9 REPLIES 9

Shaqeel
Mega Sage

Hi @Alex Saager1 

 

You need to set up an Inbound Email Action.

Here are the steps:

 

1. Navigate to System Policy > Email > Inbound Actions in ServiceNow.

2. Click on New to create a new Inbound Email Action.

3. Fill in the necessary fields:

- Name: Give a name to the action (e.g., "Create Catalog Item Request").

- Target table: Select "sc_req_item" (Service Catalog Requested Item).

- Action type: Select "Record Action".

- When to run: Define the conditions under which the action should run. For example, you can set it to run when the email subject contains a specific keyword.

4. In the Script field, write a script to create a new catalog item request.

Here is a sample script:

javascript

(function runAction(email, email_action, incident) {

var gr = new GlideRecord('sc_req_item');

gr.initialize();

gr.short_description = email.subject;

gr.description = email.body_text; gr.insert();

})(email, email_action, incident);

 

5. Click on Submit to save the Inbound Email Action.

 

Remember, the email body should contain all the necessary information to create the catalog item request. The script can be modified to parse the email body and extract the required information.

 

Please note that this is a basic example. Depending on your specific requirements, you might need to customize the script and the conditions under which the action runs.

 

Regards

Shaqeel


***********************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting "Accept as Solution" and " Helpful." This action benefits both the community and me.

***********************************************************************************************************************





Regards

Shaqeel

Hi @Shaqeel 

 

Thank you the above, following your instructions I've created the following script but for some reason the inbound action wont run.

 

I get the following error:

did not create or update sc_request using current

 

I've tried this on the request table and the requested item table to no avial.

 

What am I missing???

 

heres the script:

 

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

    // Implement email action here
    var cartID = GlideGuid.generate(null);
    var cart = new Cart(cartId);
    var item = cart.addItem('65a26f1b47b7f950f42ad0e8736d43c8');
    cart.setVariable(item, 'description', email.body_text);
    var rc = cart.placeOrder();

    var ritm = new GlideRecord('sc_req_item');
    ritm.addQuery('request', rc.sys_id);
    ritm.query();
    if (ritm.next()) {
        ritm.short_description = email.subject.toString();
        ritm.contact_type = "email";
        ritm.update();
    }

})(current, event, email, logger, classifier);

Hi @Alex Saager1 

 

Cart API is outdated. Please use CartJS. Refer the official documentation on the below link and modify your script accordingly :

https://developer.servicenow.com/dev.do#!/reference/api/sandiego/server/sn_sc-namespace/c_CartJSScop...

 

Thanks & Regards

Amit Verma


Please mark this response as correct and helpful if it assisted you with your question.

Hi @Alex Saager1 

 

Please let me know if the solution helped. If yes, request you to mark the answer as helpful and correct for others to reference. Also, please share your Inbound action script if it works.

 

Thanks & Regards

Amit Verma


Please mark this response as correct and helpful if it assisted you with your question.