AG

Dear community, I ask for your help in finding an error in my code. I can't find it myself :(
Task: go from the lower position in the organizational structure to upper division and get all the divisions, including the upper one.
My code seems logical to me, but when running it loops on one of the nodes, for example, on the Depute object (if you run it from the Engineer 1.1 object.).

I ask the respected community for help in solving the problem.

My code:
 

var gl = Context.getSelectedLanguage();
var startObjectOccs = ArisData.getSelectedObjOccs();
var myArr = [];
for (var i=0;i<startObjectOccs.length;i++){
    findUnits(startObjectOccs[i]);
}

for (var j=0;j<myArr.length;j++){
    Dialogs.MsgBox("Found divisions: " + myArr[i]);
}   

function findUnits(occ){
    var currCnxArr = occ.Cxns(Constants.EDGES_INOUT);
    Dialogs.MsgBox("Check (length of the links array):  " + currCnxArr.length);
    //var unitArr = [];
    for (i=0; i<currCnxArr.length;i++){
        if (currCnxArr[i].getSource().ObjDef().TypeNum() == 45){ //if the source of connection is a position
            Dialogs.MsgBox("Check: Next node-position " +currCnxArr[i].getSource().ObjDef().Name(gl));
            findUnits(currCnxArr[i].getSource());
        } else if (currCnxArr[i].getSource().ObjDef().TypeNum() == 43 && currCnxArr[i].getDefinition().TypeNum() == 7){ //if the source of connection is a division
            Dialogs.MsgBox("Check: Next node-division " + currCnxArr[i].getSource().ObjDef().Name(gl));
            //currCnxArr[j].getDefinition().TypeNum() == 9
            myArr.push(currCnxArr[i].getSource().ObjDef().Name(gl));
            findUnits(currCnxArr[i].getSource());
            
        }
        
    }
    return;     
}  

by Robert Goldenbaum
Badge for 'Question Solver' achievement
Posted on Tue, 07/19/2022 - 13:12

Hm, just try to use a hash-map to check if you have already worked on an object before...

var mObjOccsDone = new java.util.Hashtable();

if (!mObjOccsDone.containsKey(occ)){

      mObjOccsDone.put(occ, "")

      ....

}

0
by Kay Fischbach
Posted on Tue, 07/19/2022 - 14:48

I don't know if this fixes your problem, but it'll most certainly help:

In your findUnits function you have a for loop that iterates with a variable i that isn't declared in your function, thus your function lets the variable i bleed into the global scope of your program:

You should correct

for (i=0; i<currCnxArr.length;i++){

to

for (var i=0; i<currCnxArr.length;i++){

 

Then in your second output loop you don't use j and instead use i for the array position, making it pretty unpredictable what it'll actually output:

for (var j=0;j<myArr.length;j++){
    Dialogs.MsgBox("Found divisions: " + myArr[i]);
}

should be

for (var j=0;j<myArr.length;j++){
    Dialogs.MsgBox("Found divisions: " + myArr[j]);
}

 

0
by Anton Golovanov Author
Posted on Thu, 07/21/2022 - 10:45

Dear colleagues,
thank you very match for your answers! 
Indeed, I did not notice these stupid mistakes :( Now I figured it out, rewrote the algorithm and it all worked.

0

Featured achievement

Rookie
Say hello to the ARIS Community! Personalize your community experience by following forums or tags, liking a post or uploading a profile picture.
Recent Unlocks

Leaderboard

|
icon-arrow-down icon-arrow-cerulean-left icon-arrow-cerulean-right icon-arrow-down icon-arrow-left icon-arrow-right icon-arrow icon-back icon-close icon-comments icon-correct-answer icon-tick icon-download icon-facebook icon-flag icon-google-plus icon-hamburger icon-in icon-info icon-instagram icon-login-true icon-login icon-mail-notification icon-mail icon-mortarboard icon-newsletter icon-notification icon-pinterest icon-plus icon-rss icon-search icon-share icon-shield icon-snapchat icon-star icon-tutorials icon-twitter icon-universities icon-videos icon-views icon-whatsapp icon-xing icon-youtube icon-jobs icon-heart icon-heart2 aris-express bpm-glossary help-intro help-design Process_Mining_Icon help-publishing help-administration help-dashboarding help-archive help-risk icon-knowledge icon-question icon-events icon-message icon-more icon-pencil forum-icon icon-lock