inRels and OutRels in jArchi 1.10

Started by Mate, July 03, 2025, 14:38:33 PM

Previous topic - Next topic

Mate

I am running into a curious issue where in/outRels give an error while loop works!

$('element').each(function(e) {
    var outCount = 0;
    $('relationship').each(function(rel) {
        if (rel.source && rel.source.id === e.id) {
            outCount++;
        }
    });
    log('Element: ' + e.name + ' | Outgoing relationships: ' + outCount);
});
   
   
This code snippet works!



$('element').each(function(e) {
    // Get all outgoing relationships for this element using outRels()
    var outCount = e.outRels().length;
    log('Element: ' + e.name + ' | Outgoing relationships: ' + outCount);
});

while this one using outRels gives an error

   org.graalvm.polyglot.PolyglotException: TypeError: invokeMember (outRels) on com.archimatetool.script.dom.model.ArchimateElementProxy failed due to: Unknown identifier: outRels
   at <js>.:anonymous(relTest.ajs:15)
   at com.oracle.truffle.polyglot.PolyglotFunctionProxyHandler.invoke(PolyglotFunctionProxyHandler.java:151)
   at jdk.proxy1/jdk.proxy1.$Proxy39.accept(Unknown Source)
   at java.base/java.util.ArrayList.forEach(Unknown Source)
   at com.archimatetool.script.dom.model.EObjectProxyCollection.each(EObjectProxyCollection.java:363)

I am a novice programmer with limited jArchi experience. Likely I am doing something incorrect and will appreciate someone point that out and helping me learn.

Thanks,

Phil Beauvoir

Hi,

your variable "e" is a single object. As inRels() and outRels() is a function of a collection you need to wrap it in $(e):

$('element').each(function(e) {
    // Get all outgoing relationships for this element using outRels()
    var outCount = $(e).outRels().length;
    console.log('Element: ' + e.name + ' | Outgoing relationships: ' + outCount);
});

See https://github.com/archimatetool/archi-scripting-plugin/wiki/jArchi-Collection
If you value and use Archi, please consider making a donation.
Ask your ArchiMate related questions to the ArchiMate Community's Discussion Board.

Mate

 :) Now I know better! Thanks, Phil—I truly appreciate your help.