We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

Make the Attachment variable used in the catalog item add the file to the top of case as when using the paper clip

Gabriel Alowa
Giga Contributor

Recently Servicenow added a new variable type named attachment and it works great. Here is my question. When that variable is used on the catalog item , it attaches the file in the work note in the case created. That location is different from where the files is attached when using the paper clip . Is here a way to make the new variable attachment add the file to the top of the case as when you use the paper clip? 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron

@Gabriel Alowa 

I have shared working solution in this link below

Disable ZZ_YY prefix from attachment when added through record producer

Adding the same here for your reference:

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

2) Script as this

a) Remove the ZZ_YY

b) Then use the Copy Attachment functionality

(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);

Regards
Ankur

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

View solution in original post

17 REPLIES 17

Yes, change the table name in 2 places in the Business Rule script (once with the ZZ_YY, and once without per the sc_req_item example, then change the Business Rule to run on the sn_hr_core_case_workforce_admin table instead of sc_req_item.

@Gabriel Alowa 

yes please change it as I have shared in my script if you are referring that.

Regards
Ankur

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

davidpridemore1
Tera Contributor

If anyone else is seeing this in 2023, the VariableUtil.copy() method is now VariableUtil.copyAttachment(). so you'll need to modify this line from:

new global.VariableUtil().copy(gr.sys_id, current.getTableName(), current.sys_id); 

to:

new global.VariableUtil().copyAttachment(gr.sys_id, current.getTableName(), current.sys_id);

 

Not a huge fan of this functionality either, but this will make the BR above work again.