- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2022 02:56 AM
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
Solved! Go to Solution.
- Labels:
-
Request Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-02-2022 06:34 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2022 03:47 AM
Hi
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2022 03:55 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2022 04:04 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2022 04:10 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader