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();
Francois Du Toit on
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