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.