Need to attach an attachment from Record procedure

Bunny
Tera Contributor

Hi All,

 

I have created a Record Procedure (RP). In that RP I have created Attachment Variable.

When User Clicks on submit button that attachment should be attached to target Table.

But I'm unable to attach it in Target Table. Anyone please help me on this issue.

 

Thanks & Regards,

Anji.  

 

2 REPLIES 2

Peter Bodelier
Giga Sage

Hi @Bunny 

 

What have you tried already?


Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.

Ankur Bawiskar
Tera Patron
Tera Patron

@Bunny 

I have shared solution for this few years ago

Disable ZZ_YY prefix from attachment when added through record producer 

sharing it 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-1699278285249.png

 

2) The file present on the attachment variable

AnkurBawiskar_1-1699278284832.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