Finding Groups an Item is a member of


(Michael Cumming) #1

I would like to get a couple of groups that an item is a member of. I have played around with several versions of this and cannot get it too work.

Pseudo code is below



rule "group test"
when
    Member of gGroup changed
then

    val Group groupOne = null
    val Group groupTwo = null

    triggeringItem.getGroupNames.forEach [ i | 

        val b = gCollectionOne.members.findFirst [a | a.name == i]

        if (b !== null) 
            groupOne = b

        
        val c = gCollectionTwo.members.findFirst [a | a.name == i]

        if (b !== null) 
            groupTwo = c
    ]

    // now do operations if groupOne and groupTwo are not null

(Rich Koshak) #2
    if(triggeringItem.getGroupNames.contains("groupOneName") && triggeringItem.getGroupNames.contains("groupTwoName")) {
        // code goes here
    }

You cannot assign a new value to a val.

You cannot access vars inside a forEach lambda.

Another alternative:

    val GroupItem groupOne = triggeringItem.getGroupNames.findFirst[ g | g.name == "groupOneName" ]
    val GroupItem groupTwo = triggeringItem.getGroupNames.findFirst[ g | g.name == "groupTwoName" ]

    if(groupOne != null && groupTwo != null){
        // code goes here
    }