Forum Discussion
FindObject(xMapping, sProperties)
FindObject(xMapping, sProperties){
var aChildObjects, iNumberOfFoundObjects;
var j, iPropertyCount = 0;
var aProperty = [], aValue = [];
//Set initial object
var oInitialObject = SetInitialObject(xMapping);
//Abort if Initial object can not be set due to incorrect mapping
if (!oInitialObject.Exists)
{
Log.Error(sIndent + "The object with mapping '" + sApplication + "." + xMapping + "' does not exist. Please check mapping.");
return null;
}
//Loop through all arguments
for (var i = 1; i < arguments.length; i += 2)
{
//Set the object property/value combination
aProperty[iPropertyCount] = arguments;
aValue[iPropertyCount] = arguments[i + 1];
//Add property/value combo count
iPropertyCount++;
//Find object within the mapping
aChildObjects =VBArray(oInitialObject.FindAllChildren(aProperty, aValue, 30, true)).toArray();
iNumberOfFoundObjects = aChildObjects.length;
//No object found
if (iNumberOfFoundObjects === 0)
{
return null;
}
//Unique object found
else if (iNumberOfFoundObjects == 1)
{
return aChildObjects[0];
}
}
//Loop finished, but still more than 1 object found
Log.Message(sIndent + "Object could not be found unique. " + iNumberOfFoundObjects + " objects were found: (Last found object will be returned)");
for (j = 0; j < iNumberOfFoundObjects; j++)
{
Log.Message(sIndent + sIndent + aChildObjects
.Name + " was found with initial property '" + arguments[2] + "'."); }
return aChildObjects[iNumberOfFoundObjects - 1];
}