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

@Ankur Bawiskar It will work if I use below script(remove bae64) but again bae64 decording is not happening but it will attach in ritm.

 find_real_file.png

find_real_file.png

find_real_file.png

 

Hi,

so are you saying it's working only for text/csv file?

(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 No its not working for any of the types. Decoding is not happed till now. Only encoded file will attach if we remove sa.write/bae64 code line.

Hi,

it worked for me; you can also try to test it from background script

var gr = new GlideRecord('incident');
gr.get('bffc56dd071c01102011ff208c1ed0b9');
var fileName = 'hello.txt';
var fileContentType = 'text/plain'; // such as image/jpeg or application/pdf
var fileData = 'dGhpcyBpcyBteSB0ZXh0IGZpbGU=';

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

File data in base64

find_real_file.png

Record output

find_real_file.png

Regards
Ankur

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

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