Need to add attachments to the case from email notification

cp10
Tera Contributor

Hi,

I have a requirement to update the state value and add the attachments to the case from email.

I have created Inbound email action and tested but the attachments are stored in sys_email table instead of Case table. i tried below code but its not working, please help me on this.

Inbound Email action: Reply

 

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

        // Implement email action here
        var Finance = '';
        var regex = /FC[0-9]+/gi;
        if (regex.test(email.subject)) {
            var matchInc = email.subject.match(regex);
            Finance = matchInc[0];
        }

        if (Finance != '') {
            var num = new GlideRecord('x_bcb_fcm_case');
            num.addQuery('number', Finance);
            num.query();
            if (num.next()) {
                if (num.state == '18') {
                    num.state = 10; // Example: Set to "In Progress"
                    num.update();
                    // Get attachments from the email
                    var attGR = new GlideSysAttachment().getAttachments('sys_email', email.sys_id);
                    while (attGR.next()) {
                        attGR.table_name = 'x_bcb_fcm_case';
                        attGR.table_sys_id = num.sys_id;
                        attGR.update();

                    }
                }
            }
        }

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

@cp10 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader