Attachment not getting attached in email

Hafsa1
Mega Sage

I have RP created for CSM table, where i have used some "attachment" type variables.

when submitting case with attachments, attached using "attachment" variables, they are not populating on top of the case. Rather they are seen in activity stream.

My issue is, I have simple notification created and "include attachment" is checked but still attachments are not getting on email. even in email log it is not attached. where can be the issue?

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Hafsa1 

attachment from attachment variable is not automatically copied to the target record

check solution here which I shared for this and it should copy the file to target record

Disable ZZ_YY prefix from attachment when added through record producer 

sharing the solution again here

1) I created Async After Insert BR on the target table

2) Script as this

a) Remove the ZZ_YY

b) Then use the Copy Attachment

(function executeRule(current, previous /*null when async*/) {

	// Add your code here
	var gr = new GlideRecord("sys_attachment");
	gr.addQuery("table_name", "ZZ_YY" + current.getTableName());
	gr.addQuery("table_sys_id", current.sys_id);
	gr.query();
	if (gr.next()) {
		gr.table_name = current.getTableName();
		gr.update();
		new global.VariableUtil().copyAttachment(gr.sys_id, current.getTableName(), current.sys_id); 
	}

})(current, previous);

Output:

1) The file added to the record

AnkurBawiskar_0-1737032717111.png

 

2) The file present on the attachment variable

AnkurBawiskar_1-1737032716772.png

 

 

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

View solution in original post

12 REPLIES 12

@Hafsa1 

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

Hafsa1
Mega Sage

i have added after BR on case table

gs.info("attachment case start");
    var grnew = new GlideRecord("sys_attachment");
    grnew.addQuery("table_name", "ZZ_YYsn_customerservice_north_america_procurement");
    grnew.addQuery("table_sys_id", current.sys_id);
    grnew.query();
    while (grnew.next()) {
        gs.info("attachment case while ZZ_YY");
        grnew.table_name = current.getTableName();
        grnew.update();
        new global.VariableUtil().copyAttachment(grnew.sys_id, current.getTableName(), current.sys_id);
    }
 
in log, it is not going inside while, it is just getting below message
"attachment case start"

Hafsa1
Mega Sage

I have removed query " grnew.addQuery("table_name""ZZ_YYsn_customerservice_north_america_procurement");" and updating all records again. And it is working fine