Can I use the current object like this in the Inbound Email Action?

Kenisha Morgan
Tera Contributor

Hey Everyone, 

 

I have an inbound email action that will update a case/onboarding case in the CSM when the state of those cases ARE NOT in cancelled or closed. If the cases/onboarding cases are in a state of closed/cancelled; then, it will create a new case and the old case is the parent of the new case. 

 

Lately, we are having emails coming in, but NOT creating new cases when the state is either closed or cancelled. Nonetheless, on the sys_email table, these emails have empty targets. We read that we should use the current objects to fix the issue. Nonetheless, I want to know if I can use the current object like this? Below is our code. 

 

Can we do this? Or is it a better way to do this? 

 

else if (case_state == 3 || case_state == 7) { // Closed/Cancelled

                if (gr.getRowCount() == 0) {
                    gr = new GlideRecord(caseGR.getValue('sys_class_name'));
                    gr.initialize();
                    
                    gr.category = current.caseGR.category;
                    gr.subcategory = current.caseGR.subcategory; 
                    gr.assignment_group = current.caseGR.assignment_group;
                    gr.assigned_to = current.caseGR.assigned_to;
                    gr.short_description =current.caseGR.short_description;
                    gr.description = current.caseGR.description;
                    gr.contact_type = current.caseGR.contact_type;
                    gr.account = current.caseGR.account;
                    gr.u_investment_account = current.caseGR.u_investment_account;
                    gr.contact = current.caseGR.contact;
                    gr.parent = current.caseGR.getUniqueValue();
                    gr.comments = 'From: ' + email.origemail + '\nTo: ' + email.direct + '\nCC: ' + email.copied + '\n\nSubject: ' + email.subject + '\n\n' + email.body_text;
                    gr.work_notes = 'This case was created to manage inquires for ' + caseGR.number + ': ' + caseGR.short_description + ', which is now closed.';
                    gr.insert();

                    sys_email.instance = gr.getUniqueValue();
                    sys_email.update();
                    gs.info(" This is the NEW CASE CREATED: " + gr.number);
                    GlideSysAttachment.copy('sys_email', sys_email.sys_id, gr.getValue('sys_class_name'), gr.getUniqueValue());
                    GlideSysAttachment.copy(caseGR.getValue('sys_class_name'), caseGR.getUniqueValue(), gr.getValue('sys_class_name'), gr.getUniqueValue());
                }

 

 

 

Thank you! 

2 REPLIES 2

Mark Roethof
Tera Patron
Tera Patron

Hi there,

I assume you are pasting only a part of the script? Because what I'm seeing now will never work.

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark
2020-2022 ServiceNow Community MVP
2020-2022 ServiceNow Developer MVP

---

LinkedIn
Community article, blog, video list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Yes, I am. I just posted the script for the cases that are either in closed or cancelled. The entire script is kinda long. You want me to post it?