Forum Discussion

dicas's avatar
dicas
Occasional Contributor
5 years ago

FindChild : Error: The object does not support this property or method

Hello,

I tried to refactor my code with this below function, but i get the error in subject, when i try to access FindEx from Project.Variables.objstudioprocess

When I set a breakpoint at this line, and evaluate with debugtool:
Project.Variables.objstudioprocess   returns an 'Object'

That i can inspect and see the FindEx method available

When i try to evaluate with debugtool: 

Project.Variables.objstudioprocess.FindEx(propArray,propValues,depth=5,true,delay = 5000) 

It indeed find the tested object that i want.

When I continue the execution of the test it raises again the error.

See below the code : 

function addNewProjectVariable(parentName, variableName, type, arrayNames, arrayValues) {
if (!Project.Variables.VariableExists(variableName)) {
Project.Variables.AddVariable(variableName, type);
}
let propArray = arrayNames;
let propValues = arrayValues;


Project.Variables.variableName = Project.Variables.objstudioprocess.FindEx(propArray,propValues,depth=5,true,delay = 5000) // Error: The object does not support this property or method.
Log.Message("systemView :"+Project.Variables.projectTreeView.Name)

}
  • To answer your question:

     

    Project.Variables.variableName is not defined because there isn't a variable named variableName.  There is a variable with the name that is the content of variableName.  

     

    So, let's say variableName is "myVariable".  Then you would reference it as Project.Variables.myVariable or Project.Variables.VariableByName("myVariable").

     

    Now, as to the other issue, this might be because you're using JavaScript and JavaScript can't assign values to indexed properties directly.  So, you'll need to re-do that line like so.

     

    function addNewProjectVariable(parentName, variableName, type, arrayNames, arrayValues) {
      if (!Project.Variables.VariableExists(variableName)) {
        let localVariable = Project.Variables.AddVariable(variableName, type);
      }  // Variable is created / evaluated here already 
    else {
        let localVariable = Project.Variables.VariableByName(variableName);
    }
      let propArray = arrayNames;
      let propValues = arrayValues;
      
     localVariable = Project.Variables.objstudioprocess.FindEx(propArray,propValues,depth=5,true,delay = 5000)
      Log.Message("systemView :"+Project.Variables.projectTreeView.Name)
      
    }

     

    Alternatively, you may need to use the $set method to assign the variable value.

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    I think the problem is here.

     

    Project.Variables.variableName = Project.Variables.objstudioprocess.FindEx(propArray,propValues,depth=5,true,delay = 5000)

     

    What is "variableName" in this context?  The code doesn't know.  You've created a variable with the NAME that is stored in variableName, but that variable isn't evaluated yet.

     

    instead, replace with

     

    Project.Variables.VariableByName(variableName) = Project.Variables.objstudioprocess.FindEx(propArray,propValues,depth=5,true,delay = 5000)

     You need to use "VariableByName" because you need to evaluate what the variable is by the given name.  This is where your error is coming from, not the find.

    • dicas's avatar
      dicas
      Occasional Contributor

      Hello!

      Actually,
      to your question : What is "variableName" in this context?

       

      function addNewProjectVariable(parentName, variableName, type, arrayNames, arrayValues) {
        if (!Project.Variables.VariableExists(variableName)) {
          Project.Variables.AddVariable(variableName, type);
        }  // Variable is created / evaluated here already 
        let propArray = arrayNames;
        let propValues = arrayValues;
        
       Project.Variables.VariableByName(variableName) = Project.Variables.objstudioprocess.FindEx(propArray,propValues,depth=5,true,delay = 5000)
        Log.Message("systemView :"+Project.Variables.projectTreeView.Name)
        
      }


      See in my function i have a first part that deals with VariableName creation, isn't it already evaluated then ?

      if (!Project.Variables.VariableExists(variableName)) {
          Project.Variables.AddVariable(variableName, type);
        }  // Variable is created / evaluated here already 



      I tried your solution still : I got a new error 
      ReferenceError: Invalid left-hand side in assignment 

      • tristaanogre's avatar
        tristaanogre
        Esteemed Contributor

        To answer your question:

         

        Project.Variables.variableName is not defined because there isn't a variable named variableName.  There is a variable with the name that is the content of variableName.  

         

        So, let's say variableName is "myVariable".  Then you would reference it as Project.Variables.myVariable or Project.Variables.VariableByName("myVariable").

         

        Now, as to the other issue, this might be because you're using JavaScript and JavaScript can't assign values to indexed properties directly.  So, you'll need to re-do that line like so.

         

        function addNewProjectVariable(parentName, variableName, type, arrayNames, arrayValues) {
          if (!Project.Variables.VariableExists(variableName)) {
            let localVariable = Project.Variables.AddVariable(variableName, type);
          }  // Variable is created / evaluated here already 
        else {
            let localVariable = Project.Variables.VariableByName(variableName);
        }
          let propArray = arrayNames;
          let propValues = arrayValues;
          
         localVariable = Project.Variables.objstudioprocess.FindEx(propArray,propValues,depth=5,true,delay = 5000)
          Log.Message("systemView :"+Project.Variables.projectTreeView.Name)
          
        }

         

        Alternatively, you may need to use the $set method to assign the variable value.