Forum Discussion

ali_jafer's avatar
ali_jafer
Occasional Contributor
11 years ago

Checking for existence of a Script Unit and functions/subs defined in it

Suppose I am getteing name of Script Unit and any function defined in it as input from an external data source, if I want  to determine, whether this particular Script Unit and function is part of cur...
  • TanyaYatskovska's avatar
    11 years ago

    Hi Ali,


     


    You can use the following function:




    //JScript


    function FunctionExists(UnitName, FunctionName)


    {


     var oTC = Sys.OleObject("TestComplete.TestCompleteApplication");


     var strProjectName = /\\([^\\]+).mds$/.exec(Project.FileName)[1];


     var colFunctions = oTC.Integration.ProjectRoutinesIterator(strProjectName);


     colFunctions.Reset();


     


     var oFunc;


     while (colFunctions.HasNext())


     {


        oFunc = colFunctions.Next;


        if ((oFunc.UnitName == UnitName) && (oFunc.Name == FunctionName))


          return true;


     }


     return false;


    }