Send attachments to Mid Server

prabh
Mega Expert

Hi All,

How can I send attachments from Service now instance to a folder in mid server

41 REPLIES 41

sneha44
Kilo Explorer

Hi Ankur,

This is the error .I am getting.Could you help me out on this.

 

<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

 

Can you share the mid server script include "AttachmentSender" complete script

the error seems there

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

Hi Ankur,

 

Below Script is "AttachmentSender".

 

var AttachmentSender = Class.create();

AttachmentSender.prototype = {

initialize: function() {
ms.log('amdsa 1st line>>>>>>>>');
this.MIDSERVER_FILE_NAME = probe.getParameter('targetFileName');
this.MIDSERVER_FILE_PATH = probe.getParameter('targetPath');
this.Encoded_Data = probe.getParameter('encodedData');
this.useProxy = this.getConfigParameter("mid.proxy.use_proxy");
ms.log('amdsa 2nd line>>>>>>>>');

if (this.useProxy) {

this.proxyHost = this.getConfigParameter("mid.host");
this.proxyPort = this.getConfigParameter("mid.port");
this.proxyUser = this.getConfigParameter("mid.username");
this.proxyPass = this.getConfigParameter("mid.proxy.password");

}

this.user = ms.getConfigParameter("mid.instance.username");
this.password = ms.getConfigParameter("mid.instance.password");
this.targetPath = probe.getParameter('targetPath');
this.targetFileName = probe.getParameter('targetFileName');

},

 

getConfigParameter: function(parm) {

var m = Packages.com.service_now.mid.MIDServer.get();
var config = m.getConfig();
var res = config.getParameter(parm);
var res2 = config.getProperty(parm);
if (res) {
ms.log('amdsa res line>>>>>>>> ' + res);
return res;
} else if (res2) {
ms.log('amdsa res2 line>>>>>>>> ' + res2);
return res2;
} else {
config = Packages.com.service_now.mid.services.Config.get();
ms.log('amdsa config prop line>>>>>>>> ' + config.getProperty(parm));
return config.getProperty(parm);
}
},

 

saveToFile: function(targetPath) {

var tmpLoc;

var result = true;
var strContent = new Packages.com.glide.util.Base64().decode(this.Encoded_Data);

try {

tmpLoc = this.MIDSERVER_FILE_PATH + this.MIDSERVER_FILE_NAME;


var fos = new Packages.java.io.FileOutputStream(tmpLoc);

for (var index = 0; index < strContent.length; index++) {
fos.write(strContent[index].toString());
}
ms.log('amdsa fos close line>>>>>>>> ' + fos);
fos.close();
ms.log('amdsa File saved to: ' + tmpLoc);

} catch (e) {
ms.log('amdsa transfer Error mid server : ' + e);
result = false;
}
},

execute: function() {

var result = '';
var pushRes = true;
var saveRes = this.saveToFile(this.targetPath + this.targetFileName);
ms.log('amdsa last result line>>>>>>>> ' + result);
return result;

},

type: "AttachmentSender"

};

 

Thanks

Hi,

your mid server script include is AttachmentSender but you are calling another one

it should be this

var ddr = new AttachmentSender(); res= ddr.execute();

Regards
Ankur

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

Hi Ankur,

Give me Clarification on this var ddr = new AttachmentSender(); res= ddr.execute();

 

Thanks