I want to upload attachments through transform maps. Can anybody help??

geetikagarg
Tera Contributor

I want to upload data in contract table and the records contain attachment  also. Can any body help how to upload the attachment data.I am getting the data through excel sheet.

1 ACCEPTED SOLUTION

Then check this blog where I have recently shared the approach

is it possible to send attachment through transform map?

Tell customer to send all these details in the excel file

1) the base64encoded data of the attachment

2) file name

3) content type

once you are sure these all data is present in excel you can use onAfter transform script so that it adds attachment to that record which got created/updated

Like this

find_real_file.png

OnAfter script would be like this

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
	// Add your code here
	var fileName = source.u_file_name;
	var fileContentType = source.u_content_type; // such as image/jpeg or application/pdf
	var fileData = source.u_base64_data;

	var ecc = new GlideRecord('ecc_queue');
	ecc.initialize();
	ecc.agent = "AttachmentCreator";
	ecc.topic = "AttachmentCreator";
	ecc.name = fileName + ":" + fileContentType;
	ecc.source = target.sys_class_name + ":" + target.sys_id;
	ecc.payload = fileData;
	ecc.insert();

})(source, map, log, target);

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards
Ankur

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

View solution in original post

9 REPLIES 9

geetikagarg
Tera Contributor

@anuragtripathi can you plz help

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

So what does the excel contain?

Does it contain the file name, content type, data of file?

Regards
Ankur

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

right now all this info I can ask from the client..I currently have a scenario if I want to upload attachment and attach to a particular record of contract, then how can i do it??

Importing is done from excel..

Then check this blog where I have recently shared the approach

is it possible to send attachment through transform map?

Tell customer to send all these details in the excel file

1) the base64encoded data of the attachment

2) file name

3) content type

once you are sure these all data is present in excel you can use onAfter transform script so that it adds attachment to that record which got created/updated

Like this

find_real_file.png

OnAfter script would be like this

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
	// Add your code here
	var fileName = source.u_file_name;
	var fileContentType = source.u_content_type; // such as image/jpeg or application/pdf
	var fileData = source.u_base64_data;

	var ecc = new GlideRecord('ecc_queue');
	ecc.initialize();
	ecc.agent = "AttachmentCreator";
	ecc.topic = "AttachmentCreator";
	ecc.name = fileName + ":" + fileContentType;
	ecc.source = target.sys_class_name + ":" + target.sys_id;
	ecc.payload = fileData;
	ecc.insert();

})(source, map, log, target);

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards
Ankur

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