I am new to ARIS scripting and was trying to write a script to fetch all the group names and child group names from a selected Group. Following is my code and it is only returning the Parent group. Can someone please tell me what is wrong with my code?
var nLocale = Context.getSelectedLanguage();
function main(){
var oOutput = Context.createOutputObject();
var aGroups=ArisData.getSelectedGroups();
for (var i = 0; i < aGroups.length; i++) {
var oGroup = aGroups[i]; // Current Group
var sGroupName = oGroup.Name(nLocale); // Name of current Group
oOutput.OutputLn(sGroupName, "Arial", 10, Constants.C_BLACK, Constants.C_TRANSPARENT, Constants.FMT_LEFT, 0);
}
oOutput.WriteReport();
}
main();
Hi Liju,
You are only outputting the SELECTED content, which is the one group you had highlighted when you run the report. You need to add the sub-groups for it to be included in the outcome.
Updated script, and I changed the output to output the full path, instead of just the group name.
var nLocale = Context.getSelectedLanguage();
function main(){
var oOutput = Context.createOutputObject();
var aGroups=ArisData.getSelectedGroups();
var allGroups = new Array(); //var to capture all paths
for(var agc = 0; agc < aGroups.length; agc++) { //go through selected list to find all sub-groups
var grp = aGroups[agc];
allGroups.push(grp);
allGroups = allGroups.concat(grp.Childs(true));
}
//Output all groups
for (var i = 0; i < allGroups.length; i++) {
var oGroup = allGroups[i]; // Current Group
var sGroupName = oGroup.Name(nLocale); // Name of current Group
var sPath = oGroup.Path(nLocale); //Full path of current group
oOutput.OutputLn(sPath , "Arial", 10, Constants.C_BLACK, Constants.C_TRANSPARENT, Constants.FMT_LEFT, 0);
}
oOutput.WriteReport();
}
main();
Rgs,
Francois
Thank alot Francois. Above code works as the way i wanted. I am stuck at a new thought though. I have a model in a folder which is again in another folder. Is it possible to run a report on the parent folder to find the number of the objects in the model deep down in it ?? I would really appreciate your input :)
I wrote the following code for that and it is working on a single folder containing a value stream model. But if i try to run the same report on a model inside multiple folders then it is breaking. Can you please check this ?
var nLocale = Context.getSelectedLanguage();
function main() {
var ogroups = ArisData.getSelectedGroups();
var output = Context.createOutputObject();
for (var i = 0 ; i < ogroups.length; i++ ){
var ocurrentgroup = ogroups[i];
}
var objDefCount = ocurrentgroup.ObjDefList().length;
var ochildren = ocurrentgroup.Childs();
if ((ochildren.length > 0)) {
for ( var h = 0 ; h < (ochildren.length - 1)+1 ; h++ ) {
var ocurrentchild = ochildren[h];
}
}
var omodels = ocurrentgroup.ModelList();
if (omodels.length > 0) {
for (var i = 0 ; i < (omodels.length - 1)+1 ; i++ ){
var ocurrentmodel = omodels[i];
}
}
var oobjdefs = ocurrentgroup.ObjDefList();
if (oobjdefs.length > 0) {
for (var i = 0 ; i < (oobjdefs.length-1)+1; i++ ){
var ocurrentobjdef = oobjdefs[i];
var sObjName = ocurrentobjdef.Name(nLocale);
output.OutputLn("Object " +(i+1) +":"+ sObjName, "Arial", 10, Constants.C_BLACK, Constants.C_TRANSPARENT, Constants.FMT_LEFT, 10);
}
output.WriteReport();
}
}
main();