update ritm sysid in the target record field in Email Table

ShaziyaS4380655
Tera Contributor

G Ponsekar

 

I have a custom table "MSNOW email Request" and i have written inbound email action on this table  and whenever it is triggered log record is created into the sys_email table(OOTB) , but here into this table i want to update the target record with the  requested item sys_id which is a reference field on the MSNOW email Request table is this possible??

 

6 REPLIES 6

Ankur Bawiskar
Tera Patron
Tera Patron

@ShaziyaS4380655 

share your existing script and screenshots.

If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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

 

 
    var match = email.subject.match(/(MSN\d{7})/);
    var subj = email.subject.toLowerCase();
    if ((subj.startsWith("re:") || subj.startsWith("fw:") || subj.startsWith("fwd:")) && match) {
        gs.info("record found: " + match);
        var recId = match[0];
        var gre = new GlideRecord('x_att2_fir_net_mob_msnow_email_request');
        gre.addQuery('number', recId);
        gre.query();
        if (gre.next()) {
            gs.info("gre.parent: " + gre.parent.number);
            if (gre.parent) {
                gs.info("parent not empty");
                                    gre.work_notes = email.subject; //TO SET WORKNOTES OF MSN
                                    gre.update();
                                    var old_current = current.sys_id;
                                    gs.info(" curret.sys_id: " + current.sys_id);
                                    //current.target_table=sc_req_item;
                                    current.sys_id = gre.parent; //TO SET CURRENT AS RITM
                                    gs.info("gre.parent.: " + gre.parent);
                                    //current.needs_attention = true;
                                    current.update();
                                    gs.info("after updt curret.sys_id: " + current.sys_id);

 

                                    var rel_ritm = new GlideRecord('sc_req_item');
                                    rel_ritm.addQuery('number', gre.parent.number);
                                    rel_ritm.query();
                                    if (rel_ritm.next()) {
                                        rel_ritm.needs_attention = true; // to set need attention in RITM
                                        rel_ritm.update();
                                    }

 

                                    var sysEmailGR = new GlideRecord('sys_email');
                                    sysEmailGR.addQuery('instance', old_current);
                                    sysEmailGR.query();
                                    if (sysEmailGR.next()) {
                                        gs.info("email found");
                                        sysEmailGR.target_table = 'sc_req_item';
                                        sysEmailGR.instance = gre.parent.sys_id;
                                        sysEmailGR.update();
                                        gs.info("email updated");
                                    }

 

            }

@ShaziyaS4380655 

your script is already updating the Target field on sys_email.

I think this is not recommended practice.

Example: It's like incoming email is updating INC but the Target record on sys_email you want as PRB which is not proper.

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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

yea though updating it is not working as expected , and it's a requirement from client