Hello folks,
I am trying to sort a list of connections occurrences of a object, by the NAME of the occurrence of the target object. But I could not figure it out by myself how to do.
I have a piece of code of what I am doing:
var aCxn = p_aObjOcc.Cxns()
for(var k=0; k<aCxn.length; k++) {
obj = aCxn[k].TargetObjOcc();
var aCxn2 = obj.Cxns()
aCxn2 = ArisData.sort( aCxn2, Constants.AT_NAME, Context.getSelectedLanguage() )}
But this is not working. I know I should change the parameter Constants.AT_NAME to something that would order by the name of the occurrences of the target objects, but I dont know how to.
Any tip about how I should solve this is very very much appreciated.
Thank you very much,
Gustavo
Hi Gustavo,
as per the ARIS script help the command TargetObjOcc() is depreceated and instead the command getTarget() is recommended to be used.
Also you want to sort an array of object occurrences by an attribute, whereas the attribute values are only stored in the definition of an object as per my understanding. Maybe you need to retrieve the definition corresponding to each of the occurrences of the target object and then sort this list by the name attribute or as a shortcut use getObjDefName(int p_nLocale) which returns the "Name" attribute from the definition of this occurrence.
Hope this is of any help.
Cheers
Florian
Thank you very much for your guideness Florian!
I´ve changed the way I am getting the related objects. Instead of doing by the connections, I am using the getConnectedObjOccs. It seems it is much better to achieve what I need. The code is now like this:
var aCxn = p_aObjOcc.getConnectedObjOccs([Constants.ST_VAL_ADD_CHN_SML_1], Constants.EDGES_OUT);
for(var k=0; k<aCxn.length; k++) {
obj = aCxn[k];
var aCxn2 = obj.getConnectedObjOccs([Constants.ST_VAL_ADD_CHN_SML_1], Constants.EDGES_OUT);
aCxn2 = ArisData.sort( aCxn2, Constants.AT_NAME, Context.getSelectedLanguage() )}
Cheers,
Gustavo
Hi Gustavo,
Try this code to order your CxnOcc list (case insensitive) :
var aCxn = p_aObjOcc.Cxns(); for(var k=0; k<aCxn.length; k++) { obj = aCxn[k].getTarget(); var aCxn2 = obj.Cxns(); aCxn2.sort(sort_cxnoccs_by_name); //here the list is sorted }
function sort_cxnoccs_by_name(a, b){ var nameA = a.getDefinition().Name(lng).toLowerCase().trim(); var nameB = b.getDefinition().Name(lng).toLowerCase().trim(); if(nameA < nameB){ return -1 }else{ return 1; } }
I did not try it, but it should work.
Let me know if it solves your problem.
Best Regards,
Romain Tricarico
Thank you very much for you code Romain!
I´ve changed the way I was retrieving the related objects, and now I am getting an ordered list. Take a look at my previous answer to Florian to see the code.
I haven´t tested your solution, but I might use it some other time.
Merci beaucoup mon ami!
Best Regards,
Gustavo