Forum Discussion

rndasa's avatar
rndasa
Occasional Contributor
7 years ago
Solved

Runner.CallMethod not working when passing function name as param from spreadsheet

Runner.CallMethod not working when passing function name as param from spreadsheet

  • You are missing parentheses while calling  _impl_verificationManager() function:

     

    var ResultParam = Runner.CallMethod(_impl_verificationManager(),tcInfo,tcData);

     

6 Replies

  • baxatob's avatar
    baxatob
    Community Hero

    Obviously something goes wrong.

     

     

    P.S. Better if you will provide more details about what (and how) you do - code sample, screenshot, task you want to solve etc.

  • rndasa's avatar
    rndasa
    Occasional Contributor

    ACTUAL CALLING ROUTINE:

    function tester(){
    tcInfo =[0,0,"TC333_VERIFY","TC_EXPT","TC_ACTUAL","NULL"]
    tcData =[0,0,"TC333","ABC"]
    verificationManager(tcInfo,tcData)
    }

    IMPLEMENTATION CLASSES

     

    function verificationManager(tcInfo,tcData)
    {
    try
    {
    var ResultParam = Runner.CallMethod(_impl_verificationManager,tcInfo,tcData);
    
    }
    catch (e)
    {
    Log.Error("Error occured while executing 'verificationManager' and error description is:" + e.description);
    }
    finally
    {
    Log.Message(ResultParam+"--------------"+ tcInfo[3]+"--------------"+ tcInfo[4]+"--------------"+ tcInfo[5]);
    }
    }
    
    function _impl_verificationManager(tcInfo,tcData ){
    var C = eval(tcInfo[3]+ "(" + tcData + ")" )
    return C
    }
    
    function TC333_VERIFY(K){
    Log.Message(K)
    return 1
    }
    • baxatob's avatar
      baxatob
      Community Hero

      You are missing parentheses while calling  _impl_verificationManager() function:

       

      var ResultParam = Runner.CallMethod(_impl_verificationManager(),tcInfo,tcData);

       

  • rndasa's avatar
    rndasa
    Occasional Contributor

    I tried with /without braces, But always giving "function expected" error/reference error. And I  did  "eval "as well.

    var ResultParam = eval(Runner.CallMethod(_impl_verificationManager(),tcInfo,tcData));

    Here is my requirement: I have two arrays.In array1 contain functionNames as well.Array2 contains soma required parameters.

    I am trying to passing these two arrays as parameters into a function. Which has to call  on-demand array[x](Array2) where xth element is function name. Iam trying couple of models , some of them are not able to call,some of them are not able to return values into resultparam. 

    • tristaanogre's avatar
      tristaanogre
      Esteemed Contributor

      First parameter of Runner.CallMethod has to be a string of the format unit_name.method_name.  So, if you have a script method called "Blah" in unit "MyUnit" with two parameters, you would call

       

      Runner.CallMethod('MyUnit.Blah', 'value1', 'value2')

      So, you need to make sure that, whatever that first value is of _impl_verificationManager returns a string in the desired format.

       

      While Runner.CallMethod is noted as obsolete, I'm not sure that it's going away any time soon.

       

      If, however, you are using JavaScript, you could kind of play with the same idea but using classes.  Say, for example, you have a class like below.  Note that it's best to define the class in a single code unit:

       

      class foo{
          constructor(){
               this.bar = 'This is my bar';
          }
      writeBar(){
      Log.Message(this.bar);
      } } module.exports = foo;

      If you want to call the "writeBar" method in some other unit, you can do it something like this.

       

      function runClassMethod(className, methodName){
          var localClass = require(className);
          var localObject = new localClass();
          localObject[methodName]();
      }

      function test(){
      runClassMethod('foo', 'writeBar');
      }

      Now, this is just a demonstration of the concept.  Obviously, there's more complexity that would need to be applied to do what you want (different parameters, reading values in from spreadsheet, etc), but this is a legitimate replacement for Runner.CallMethod.