collectionsxpagesxpages-ssjs

how to loop through sessionScope in SSJS / XPages?


I have a function to go through all sessionScopes:

function clearMap( map:Map ){ // Get iterator for the keys
    var iterator = map.keySet().iterator();  // Remove all items 
    while( iterator.hasNext() ){  
        //would like to read here the keyValue
    }
}

clearMap(sessionScope);

I would like to read the key value for each item in the map. (keys ending with _languagecode I would like to remove) but how can I do this?


Solution

  • With iterator.next()you have access to the key itself so you should be able to do something like this in SSJS:

    function clearMap( map:Map ){ // Get iterator for the keys
        var iterator = map.keySet().iterator();  // Remove all items 
        while( iterator.hasNext() ){  
            var key = iterator.next();
            if (key == 'something you want to test for') {
                map.remove(key);
            }
        }
    }