Send attachments to Mid Server
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-28-2017 12:15 AM
Hi All,
How can I send attachments from Service now instance to a folder in mid server
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-17-2021 09:49 AM
Hi Ankur,
Any update ,I was stuck in same step with same error.Could you help me out
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-17-2021 09:01 PM
So what is not working?
Can you share what script you are using and what is functionality required?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-17-2021 10:09 PM
Hi Ankur,
Below is the Script
transferattachment();
function transferattachment() {
// var StringUtil = Packages.com.glide.util.StringUtil;
// var sa = new Packages.com.glide.ui.SysAttachment();
var gr = new GlideRecord("sys_user");
gr.addEncodedQuery("nameLIKEamutha"); //fetches ritms created on today
gr.query();
var contents = "";
contents = contents + 'User Name' + "||"; //add more columsn whatever you want here
contents = contents + 'First Name' + "||";
contents = contents + 'Last Name' + "||";
contents = contents + "!##!";
while (gr.next()) {
contents = contents + "\n";
contents = contents + gr.user_name + "||"; //add more columsn whatever you want here
contents = contents + gr.first_name + "||";
contents = contents + gr.last_name + "||";
contents = contents + "!##!";
}
var attachment = new Attachment();
//attachment.write('TablenameFileToAttach','SysIDOfRecord','Filename','TypeOffile','ContentOfFile')
var attachmentRec = attachment.write('sc_req_item', '33386c181b10f010a76243f0b24bcb8a', 'Test TextFile from servicenow' + ".txt", "text", contents);
try {
var fileName = 'Test TextFile from servicenow';
var ftpFilePath = 'e:\\ServiceNow' +'\\MIDServer_Integration' + '\\agent' + '\\export' + '\\QA_Export'; // Update the Path
var grg = new GlideRecord('sys_attachment');
grg.get('2708ab2f1b603010136aa9f3b24bcb29');
var StringUtil = new GlideStringUtil();
var gsis = GlideSysAttachmentInputStream(grg.sys_id.toString());
var ba = new Packages.java.io.ByteArrayOutputStream();
gsis.writeTo(ba, 0, 0);
ba.close();
var encData = StringUtil.base64Encode(ba.toByteArray());
//var ddr = new AttachmentSender();
//var res = ddr.execute();
var jspr = new JavascriptProbe('INTEG_DEV_US1_01');
jspr.setName('FileToMidServer');
jspr.setJavascript("var ddr = new AttachmentSender();res = ddr.execute();");
//jspr.setJavascript(res);
jspr.addParameter("targetFileName", fileName);
jspr.addParameter("encodedData", encData);
jspr.addParameter("targetPath", ftpFilePath);
jspr.create();
gs.log('amdsa transfer Completed');
} catch (e) {
gs.log('amdsa transfer Error mid server : ' + e);
}
Thanks,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-17-2021 10:44 PM
So what error you are getting?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-17-2021 11:05 PM
Hi Ankur,
This is the error .I am getting.
<results error="Caused by error in JavaScript probe 'file' at line 1 ==> 1: var ddr = new MlAttachment(); res= ddr.execute(); " probe_time="0" result_code="900000"> <result error="Caused by error in JavaScript probe 'file' at line 1 ==> 1: var ddr = new MlAttachment(); res= ddr.execute(); "> <output>Evaluation error: Caused by error in JavaScript probe 'file' at line 1 ==> 1: var ddr = new MlAttachment(); res= ddr.execute();</output> </result>
Thanks