Scheduled CSV Export filename change

Hi Experts 

I am running an script in scheduler record to export csv for some specefic date of every month.

If you refer below script i have set the export path as below

Existing Export Path:

var path = "c:\\example\\tickets.csv";

tickets are being exported , but now i have a requirement for change the filename of export to export date. For example tickets_07032016.csv

I tried to add below variables and set " var path ="c:\\example\\tickets'" js "'" 

var d = new XMLDate( new Date() );
var js = d.getSCDateTimeString()

Do have any idea how we can add js (date) in export filename ?

Below is complete working script for reference.

var tickets = new SCFile("probsummary");
var query = "number#\"IM1000\" and problem.status=\"Work In Progress\"";
var rc = tickets.doSelect(query);

if (rc == RC_SUCCESS)
	var layout = new SCFile("format");
	var rr = layout.doSelect("name=\"probsummary.qbe.g\"");
	var path = "c:\\example\\tickets.csv";
	var delim = "csv"; // $L.delim = ","
	var header = true;
	var rteCode = new SCDatum();
	var rteNames = new SCDatum();
	var rteValues = new SCDatum();
	system.functions.rtecall("callrad", rteCode, "us.dump.delimited", rteNames, rteValues, false);


  • Verified Answer


    I have tested using this JS and the result for the filename is "tickets 03-07-16 07-46-39.csv" like "tickets MM-DD-YY HH-MM-SS"

    var jsdate = d.getSCDateTimeString();
    jsdate = jsdate.replace(/\:/g,"-");
    jsdate = jsdate.replace(/\//g,"-");

    var path ="c:\\tickets " jsdate ".csv";



  • Thanks PLP

    it worked for me, thanks a lot.

    I need one more help , in query i want to export record which was opened previous month.

    var query = "problem.status=\"Work In Progress\"";

    For example ..if i am exportig report in march month then report should have data for feb month, means Only incident opened in last month and status as WIP.


  • Hello,

    Please try this code:

    var actualdate = new Date();
    var actualmonth = actualdate.getMonth() 1;
    if (actualmonth==1){
    var previousmonth = 12;
    var previousyear = actualdate.getFullYear()-1;
    var startdate = "'01/" previousmonth "/" previousyear "'";
    var enddate = "'01/" actualmonth "/" actualdate.getFullYear() "'";
    var previousmonth = actualmonth-1;
    var previousyear = actualdate.getFullYear();
    if (previousmonth<10){
    previousmonth = "0" previousmonth;
    if (actualmonth<10){
    actualmonth = "0" actualmonth;
    var startdate = "'01/" previousmonth "/" previousyear "'";
    var enddate = "'01/" actualmonth "/" actualdate.getFullYear() "'";

    var query = "flag=true and problem.status=\"Work In Progress\" and open.time>" startdate " and open.time<" enddate;


  • Thanks LPP

    However i am still testing the code, but in a first cut it worked. 

    Thanks a lot.



  • Dear PLP

    I need one more help, id it possible to export file to some share drive and not to local server. i tried to put export shared path but i get below errors in service manager.

    3232( 3708) 04/22/2016 10:11:12 RTE E unable to open connection (,connect)
    3232( 3708) 04/22/2016 10:11:12 RAD E File \z:\TMP\2016-03_open_tickets.csv could not be opened.

    3232( 3708) 04/22/2016 10:11:12 RAD E Unrecoverable error in application: us.dump.delimited on panel prompt

    shared folder is accessible via server via windows explorer.