Send attachments to MID Server
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-07-2017 08:24 AM
Hello guys,
I need to send an attachment to a folder of MID Server .
The idea is:
- Create an incident
- Attach a file to the incident
- Click on submit
- Starts a business rule that sends the attachment to a folder of mid server.
I have found some discussions about this argument but honestly is not totally clear for me.
Could you please help me to understand which are the steps to implement this functionality?
Thanks in advance,
Giuseppe
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-08-2017 12:37 AM
Hi Giuseppe
Please go through the bellow thread it may be helpfull to you:
Sending Request Attachments via FTP or Export to Mid Server
Send attachments to Mid Server
Thanks & Regards
Haseena
PS: Hit like, Helpful or Correct depending on the impact of the response
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-14-2017 06:10 AM
Hi,
I have followed your links and I did the following
The business rule runs correctly. The script include doesn't.
Should I do something else?
Thanks,
GIuseppe
1. Business rule:
*************************************
(function executeRule(current, previous /*null when async*/) {
var gr = GlideRecord('sys_attachment');
gr.addQuery('sys_id', '018e9a594f12020031577d2ca310c75c');
gr.query();
if(gr.next()){
var fileName=gr.file_name;
gs.log("Attachment trovato : " + fileName);
var sa = new GlideSysAttachment();
var binData = sa.getBytes(gr);
var strData = String(Packages.java.lang.String(binData));
var encData =GlideStringUtil.base64Encode(strData);
var ftpFilePath = "C:\\Test\\";
var jspr = new JavascriptProbe('DEMO3_MIDSERVER');
jspr.setName('FileToMidServer');
jspr.setJavascript("AttachmentSender");
jspr.addParameter("targetFileName",fileName);
jspr.addParameter("encodedData",encData);
jspr.addParameter("targetPath",ftpFilePath);
jspr.create();
gs.log('Completed Mid Server log');
}
})(current, previous);
*************************************
2.MID SERVER SCRIPT INCLUDE
var AttachmentSender = Class.create();
AttachmentSender.prototype = {
initialize : function() {
gs.log("INIZIO ESECUZIIONE MID SERVER SCRIPT INCLUDE");
this.MIDSERVER_FILE_PATH = "C:\\Test\\";
this.MIDSERVER_FILE_NAME = probe.getParameter('targetFileName');
this.Encoded_Data = probe.getParameter('encodedData');
this.useProxy = this.getConfigParameter("mid.proxy.use_proxy");
if (this.useProxy){
this.proxyHost =this.getConfigParameter("mid.proxy.host");
this.proxyPort =this.getConfigParameter("mid.proxy.port");
this.proxyUser =this.getConfigParameter("mid.proxy.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){
return res;
}
else if (res2){
return res2;
}
else{
config = Packages.com.service_now.mid.services.Config.get();
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(targetPath);
//for(var index=0 ; index ;0);
}
catch(e){
}},
execute: function() {
var result = '';
var pushRes = true;
var saveRes = this.saveToFile(this.targetPath+ this.targetFileName);
return result;
},
type : "AttachmentSender"
};
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-14-2017 06:33 AM
I look from Queue that the error is "NOT SENSOR DEFINED".
I tried to create a new sensor but it wants a PROBE. My probe is not registered anyplace. Is only called in the script with the jspr.setName();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-03-2017 08:04 PM
Did you find any solution?