See the function getPackageTreeIDString(package) in this script:https://github.com/GeertBellekens/Enterprise-Architect-VBScript-Library/blob/master/Framework/Utils/Util.vbs
That basically does the same as #Branch#
Geert
Thank you!
I'm almost there...
I had a slighlty different approach, because at first I didn't quite understand what you did. But I think I ended up with basically the same thing, but more buggy and not fully working

I initiate the function like this:
var allPackages = new Array();
allPackages[0] = thePackage.PackageID;
allPackages = getChildPackageIDs(allPackages, allPackages);
Session.Output("RETURNED: " + allPackages);
var queryString = "SELECT ... IN (" + allPackages.join(", ") + ")
Then my function
getChildPackageIDs:
function getChildPackageIDs(allPackageIDs /* : Array of PackageIDs */, parentPackageIDs /* : Array of PackageIDs */) //Output: Array of PackageIDs
{
// Array.join doesn't work if array only has one value, how do I improve this temporary solution?
if (parentPackageIDs.length == 1)
{
parentPackageIDs.push("9999999");
}
var sqlQuery = "SELECT package.Package_ID FROM t_package package WHERE package.Parent_ID IN (" + parentPackageIDs.join(", ") + ")";
var queryResult = Repository.SQLQuery(sqlQuery);
var DOMDoc = XMLParseXML(queryResult);
var childPackageIDs = XMLGetNodeTextArray( DOMDoc, "//Row/Package_ID" );
allPackageIDs = allPackageIDs.concat(childPackageIDs);
// Without this the function returns once per iteration and over-writes the recursive allPackageIDs...?
if ( childPackageIDs.length > 0)
{
getChildPackageIDs(allPackageIDs, childPackageIDs)
}
if ( childPackageIDs.length == 0 )
{
Session.Output("RETURN: " + allPackageIDs)
return allPackageIDs;
}
}
Some problems.
1. I can't use Array.join if the array onlye has one value. I tried to have an if-statement in the
var sqlQuery, but didn't get it to work, so a temporary solution is to add a 'dummy'
PackageID. Any suggestions how I can improve that?
2. Without the if-statements in the end of the function, the returned
allPackageIDs wrote over each other, with the final
allPackageIDs just containing the top-level childpackages.
3. If I print out the return of the function in the last if-statement,
Session.Output("RETURN: " + allPackageIDs), this is the correct array of PackageIDs. However, when I print the returned array after I intiate the function
Session.Output("RETURNED: " + allPackages) (first code-box) it returns undefined, and the query obviously doesn't work then.
Edit: found a missing ; on the line
allPackages = getChildPackageIDs(allPackages, allPackages), but same issue.
How can it be that the return is correct in the function, but the actually returned array is undefined?
From System Output:
RETURN: 3205, 9999999, 3354, 3355, 3357, 3356
RETURNED: undefinedThank you for your excellence guidance
