Copy Attachment from File attachment field to same record so it will appear in Manage attachment

Pritam Mangrulk
Mega Contributor

Hi All,

I want to copy attachment from File attachment field created on incident table to same record so it will show in manage attachment at the top of the record, can you please help.

I tried GlideSysAttachment.copy function but it didn't work.

 

Thanks,

Pritam

1 ACCEPTED SOLUTION

Hi,

please update the script as this

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

	// Add your code here
	GlideSysAttachment.copy('ZZ_YY' + current.getTableName(), current.sys_id, current.getTableName(), current.sys_id);

	// rename the table_name
	var gr = new GlideRecord("sys_attachment");
	gr.orderByDesc('sys_created_on');
	gr.addQuery("table_sys_id", current.sys_id);
	gr.setLimit(1);
	gr.query();
	if (gr.next()) {
		gr.table_name = current.getTableName();
		gr.update();
	}

})(current, previous);

Regards
Ankur

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

View solution in original post

9 REPLIES 9

This is not working, the problem is that ServiceNow appends 'ZZ_YY' before target table name by default.

For example, if we write:

GlideSysAttachment.copy('ZZ_YYx_my_source_table', source_sys_id, 'u_target_table', target_sys_id);

Then in sys_attachment, the target table name is 'ZZ_YYu_target_table' and not 'u_target_table'.

How can i copy from specific fields if it file attachment field more than 1.

********************************************************************************************************
Please appreciate the efforts of community contributors by marking the appropriate response as the correct answer and helpful. This may help other community users to follow the correct solution in the future.

********************************************************************************************************
Cheers,
Prashant Kumar
ServiceNow Technical Architect


Community Profile LinkedIn YouTube Medium TopMate
********************************************************************************************************

Thank you!

I didn't know where attachments were stored using attachment fields. My error was that I tried directly with the pure table and I needed to add ZZ_YY

Pritam Mangrulk
Mega Contributor

Hi Ankur,

Thanks for quick reply, but it is not working.

 

Best Regards,

Pritam

Hello Pritam. I have a similar requirement. And this script isn't working for me. It will be great if you could tell me how you did it.