IT Process Automation

Expand all | Collapse all

Run_JavaScript Operator Not working

  • 1.  Run_JavaScript Operator Not working

    Posted Apr 16, 2018 01:29 AM

    Hi All,

    I am trying to read from a log file and calculating the count for Error , but when i do the calculation in script it gives me an error ie  TypeError: Cannot read property "length" from null (#4).

     

    Source Code
    var count = Process.fileContents.match(/ERROR/g).length;


    Process.errorCount = count;



  • 2.  Re: Run_JavaScript Operator Not working
    Best Answer

    Posted Apr 16, 2018 02:10 AM

    String.prototype.match() - JavaScript | MDN 

    The method 'match' returns null when it finds no match.  Perhaps you might consider doing something like this:

    var matches = [];
    var count = 0;
    matches = Process.fileContents.match(/ERROR/g);
    if (matches != null) {
      count = matches.length;
    }

    Regards,

    James



  • 3.  Re: Run_JavaScript Operator Not working

    Posted Apr 16, 2018 05:47 AM

    thanks