Interested in a ServiceNow event built for developers? Registration for now[dev]26 is officially open!

Disable ZZ_YY prefix from attachment when added through record producer

Chenab Khanna
Tera Expert

Hi,

I have a 'attachment' type variable in my record producer which i have made mandatory. When the user uploads any attachment, i want the attachment to get saved in the record created. But instead, it is hiding it.

I can see the entry created in sys_attachment but under table name field, a prefix ZZ_YY is getting added which is making the attachment hidden.

Please find the field below - 

find_real_file.png

 

Record in sys_attachment - 

find_real_file.png

Can anyone help me get this attachment added in the record as it happens when add any attachment from here - 

find_real_file.png

1 ACCEPTED SOLUTION

@Chenab Khanna 

This worked well for me

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().copy(gr.sys_id, current.getTableName(), current.sys_id); 
	}

})(current, previous);

Output:

1) The file added to the record

find_real_file.png

2) The file present on the attachment variable

find_real_file.png

Regards
Ankur

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

View solution in original post

57 REPLIES 57

was having trouble getting the interaction and case records to add the attachment.  will give this a try and let you know if it worked!

@Ankur Bawiskar 

I tried this logic, but the attachment is appearing only in the Activity section and is not being attached to the top of the record.

In my case, when I upload an attachment, remove it, and then upload another one, the first attachment is attached to the record, while the second appears only in the Activity section.

After implementing this business rule, only the second attachment is retained; however, it is not attached to the top of the record.

Gabriel Alowa
Giga Contributor

This is still not working for me. here is what I did with the table named sn_hr_core_case_workforce_admin.

What am I missing?

find_real_file.png

Hi,

please check any cross scope access issue

Regards
Ankur

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

Not applicable

line 5: replace with "ZZ_YY[...]" with "table_name" since this is the correct name of the attribute in the Attachment Table.