AutoSys Workload Automation

Expand all | Collapse all

Cannot use WriteToFile function ([JavaPackage java.io.File] is not a function)

  • 1.  Cannot use WriteToFile function ([JavaPackage java.io.File] is not a function)

    Posted May 26, 2016 10:54 AM

    Hi all.

    I installed the new DE 12.0 with the embedded DB. The service and the DB work without problems.

    I have a problem when i try to write a control file on the master server using an alert.

    I created the alert with the option "run this JavaScript" anche the JS is:

     

    "var tipoWrite = true;

    function WriteToFile(fileName, strContent, tipoWrite) {

      var file = new java.io.File(fileName);

      var printResult = new java.lang.String();

      printResult = '';

      var pw = new java.io.PrintWriter(new java.io.BufferedWriter(new java.io.FileWriter(file, tipoWrite)));

      printResult = printResult + strContent+'\n';

      pw.print(printResult);

      pw.flush();

      pw.close();

    }

    var fileName='destinationPATH'+WOB._name+'.'+WOB._qualifier;

    var applTstamp=APPL._SYEAR+'-'+APPL._SMM+'-'+APPL._SDD+' '+APPL._SHH+':'+APPL._SMN+'.'+APPL._SSS;

    var fileContent = APPL._name+'|'+APPL._gen+'|'+WOB._name+'|'+WOB._qualifier+'|'+applTstamp;

    WriteToFile(fileName, fileContent, tipoWrite);

     

    var fileName='destinationPATH2'+WOB._name+'.'+WOB._qualifier;

    var applTstamp=APPL._SYEAR+'-'+APPL._SMM+'-'+APPL._SDD+' '+APPL._SHH+':'+APPL._SMN+'.'+APPL._SSS;

    var fileContent = APPL._name+'|'+APPL._gen+'|'+WOB._name+'|'+WOB._qualifier+'|'+applTstamp;

    WriteToFile(fileName, fileContent, tipoWrite);"

     

    the JS can't write the file and i read in the error log "TypeError: [JavaPackage java.io.File] is not a function, it is org.mozilla.javascript.NativeJavaPackage. (<cybscope>#5)".

    The java version is 1.6.0_39.

     

    what can i do fix this error?

     

    Thank you all.



  • 2.  Re: Cannot use WriteToFile function ([JavaPackage java.io.File] is not a function)

    Broadcom Employee
    Posted May 26, 2016 11:50 AM
      |   view attached

    You can enable Java methods calls from JavaScript scripts in Admin perspective "Topology -> Configure Shared Parameters -> Internal -> Show Advanced Parameters" section;

     

    Set the property "Allow Java calls in JavaScript" to true, and save the change.

     

    See the docs; https://docops.ca.com/ca-wla-de/12-0/en/administrating/configuring/configuring-the-server-using-the-admin-topology#ConfiguringtheServerUsingtheAdminTopology-EnableJavaMethodCallsinJavaScriptScripts

     

    For DE R12 Build 38, the Java version is 1.8.0_51

     

    Thank you!



  • 3.  Re: Cannot use WriteToFile function ([JavaPackage java.io.File] is not a function)

    Posted May 26, 2016 12:04 PM

    Thank you so much.

    The alert now is working.