Pull requested for details from inbound email to create request

Community Alums
Not applicable

Hi Experts,

We have a requirement to create a Request from an inbound email action, which is working fine with my existing code. The client wants us to populate Requested for details from the Email Body. The format of the email would look something like this:

Requested By: (User Name)

Email address: (email address)

I'm not very good at coding, so kindly help me with this requirement.

 

Existing code is as below:

(function runAction(/*GlideRecord*/ current, /*GlideRecord*/ event, /*EmailWrapper*/ email, /*ScopedEmailLogger*/ logger, /*EmailClassifier*/ classifier) {
 
    var cartId = GlideGuid.generate(null);
    var cart = new Cart(cartId);

        var item = cart.addItem('sys_ID_of_catalog_item');
        cart.setVariable(item, 'short_description', email.subject.toString());
        cart.setVariable(item, 'description', email.body_text);
        cart.setVariable(item, 'assg_group', 'sys_id');
       
        var rc = cart.placeOrder();

        var ritmRec = new GlideRecord("sc_req_item");
        ritmRec.addQuery("request", rc.sys_id);
        ritmRec.query();
        if (ritmRec.next()) {
            ritmRec.short_description = email.subject.toString();
            ritmRec.comments = "received from: " + email.origemail + "\n\n" + email.body_text;
            ritmRec.contact_type = "email";
            ritmRec.update();
        }
       // update target in email table, as it won't be updated as the record was inserted through cart API
        if (rc != '') {
            var email_rec = new GlideRecord('sys_email');
            email_rec.get(sys_email.sys_id);
            email_rec.instance = rc.sys_id;
            email_rec.target_table = "sc_request";
            email_rec.update();
        }

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

Thanks in advance.

11 REPLIES 11

Here is the screenshot.

SagarGarige_0-1736426327467.png

 

@Runjay Patel  please find above screenshot of "When to run".