Critical Developers

Programmers Knowledge Base

Execute Javascript function in a Javascript file in Automation Anywhere

Execute Javascript function in a Javascript file in Automation Anywhere

Here, I will show you an example on how to Execute Javascript function in a Javascript file in Automation Anywhere.


Steps are below:-

Step-1) Lets create a  javascript file as scripts.js as shown below:-

//-------------JS Funtion to get dates between two dates---------------


WScript.StdOut.WriteLine(fnGetDateListInDateRange());


function fnGetDateListInDateRange() {

  var addDays = WScript.Arguments.Item(2);

  var startDate = WScript.Arguments.Item(0);

  var endDate = WScript.Arguments.Item(1);

  startDate = new Date(startDate);

  endDate = new Date(endDate);

  //

  if (startDate > endDate)

        {

            return "-1";

        }

  //

  var outputDate = new Array();

  var tmpDate = new Date(startDate);

  do {  

    outputDate.push(new Date(tmpDate));

    tmpDate.setDate(tmpDate.getDate() + parseInt(addDays));

  } while (tmpDate <= endDate);

  //

  return outputDate;

}


Step-2) Now call scripts.js using RunScript command in AA as shown below:-



Step-3) Run the task

Thats it !

Loading