- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-31-2017 08:56 AM
Hi
Let's say I have a mid server in C:\MIDServer\Server1\agent . I want to access a file that is placed in the agent folder (or any sub-folder) in my MID Server script include. Could someone help me on how to specify the path to that file ?
E.g. if the file name is abc.xml that is placed in agent folder, can I pass the path as "C:\MIDServer\Server1\agent\abc.xml" ?
Solved! Go to Solution.
- Labels:
-
Team Development
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-31-2017 09:03 AM
Hello Durga,
Yes, you can pass the folder directory as you mentioned in your example.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-03-2018 01:53 PM
Using the blog below I was able to setup a pdf file to be posted on the mid server.
http://www.john-james-andersen.com/blog/service-now/javascriptprobe-and-mid-server-script-includes.html
Is it possible to control the folder path where the file is posted to? Currently it is posted directly in the agents folder.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-05-2017 01:34 PM
I have tried it and it works. Just want to add that while passing the path as is, java escapes back slash character. So replace backslashes with doublebackslashes to make it work.
E.g. you path is "C:\Input\abc.text", then we have to pass "C:\\Input\\abc.text", in the script include.
Hope this is helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-10-2017 01:21 PM
Hi,
Can you please share your script include ? I need to do the same thing and this is the first time I am working with a mid server.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-11-2017 09:24 AM
Sure. Here is a sample MID Server script include, and the necessary code to call it.
MID Server Script Include (FileExportCSVDelimiter) : This code creates a csv file from sc_task table in the folder path specified in the DEST variable.
var FileExportCSVDelimiter = Class.create();
FileExportCSVDelimiter.prototype = {
initialize: function () {
//
// Common Java References
//
this.PrintWriter = Packages.java.io.PrintWriter;
this.File = Packages.java.io.File;
this.StringReader = Packages.java.io.StringReader;
this.InputStream = Packages.java.io.InputStream;
this.ByteArrayInputStream = Packages.java.io.ByteArrayInputStream;
this.FileOutputStream = Packages.java.io.FileOutputStream;
this.FileInputStream = Packages.java.io.FileInputStream;
this.BufferedReader = Packages.java.io.BufferedReader;
this.InputStreamReader = Packages.java.io.InputStreamReader;
this.String = Packages.java.lang.String;
// Unused
},
execute: function() {
var payLoad = '';
var DEST = "C:\\MID Server\\Test Folder\\test1.csv";
var towrite = '';
var tocount = 1;
var writer = new this.PrintWriter(DEST, "UTF-8");
var gr = new GlideRecord('sc_task');
gr.setLimit(10);
gr.query();
while(gr.next()){
//Comma Separated
if(tocount == 1){
tocount += 1;
towrite = '"Number","Active","Description"';
writer.println(towrite);
towrite ='';
towrite += '"' + gr.getDisplayValue('number') + '",';
towrite += '"' + gr.getDisplayValue('active') + '",';
towrite += '"' + gr.getDisplayValue('description') + '"';
writer.println(towrite);
}
else{
towrite ='';
towrite += '"' + gr.getDisplayValue('number') + '",';
towrite += '"' + gr.getDisplayValue('active') + '",';
towrite += '"' + gr.getDisplayValue('description') + '"';
writer.println(towrite);
}
}
writer.close();
},
type: FileExportCSVDelimiter
};
Code to call the script include : Works whereever server script can be run - like scheduled jobs or ui actions etc.
var midServer = 'MID_SERVER_NAME';
var jspr = new JavascriptProbe(midServer);
jspr.setName('FileExportCSVDelimiter');
jspr.setJavascript('var file = new FileExportCSVDelimiter(); res = file.execute();');
jspr.create();
Hope this is helpful!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-06-2018 02:52 AM
how and where did you place the path? i have a xml file in a directory on the midserver and want to import ("grab") that xml file. I dont have ftp or scp available. But since its on the midserver i hoped it could get it by fileshare.