is it possible to send attachment through transform map?

jobin1
Tera Expert

Hi All

My requirement is business will be encoding the attachment and sending that encoded value in excel format and the same we need to decode and transfer to ritm form via transform map.

So is it possible to do so? if yes how?. what transform script we need to use to achieve this functionality 

1 ACCEPTED SOLUTION

Hi,

So you can use this in global scope

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

Regards
Ankur

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

View solution in original post

32 REPLIES 32

Community Alums
Not applicable

Hi @jobin ,

This won't work since the attachment is an embedded file and not the actual content

Not using Transform map. But below thread could be useful if you want to do it using powershell

Bulk Loading Attachments to ServiceNow With PowerShell

 

Mark my answer correct & Helpful, if Applicable.

Thanks,

Sandeep

Ankur Bawiskar
Tera Patron
Tera Patron

@jobin 

You should be knowing these details in order to work

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

(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 sa = new GlideSysAttachment();
	sa.write(target, fileName, fileContentType, fileData);

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

Regards
Ankur

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

@Ankur Bawiskar 

 

I was also going on the same way and one doubt what will be the target filed which I need to select since  I am not able to see attachment  option in target filed but same is(attachment) auto populated in source filed.

Hi,

don't use any field map for adding the attachment.

I mentioned to use onAfter transform script since in that script you already know which is the target record.

Regards
Ankur

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