I missed a method on the $identity
object, this can actually be done in a more simple way.
There is a method getLinksByAppIdOrName(String appId, String appName)
that as it states returns accounts given an id or name of an application.
Including this results in the following transform:
{
"attributes": {
"value": "#foreach($link in $identity.getLinksByAppIdOrName(\"2c918088814e6a610181686b56977fa8\",null))#if($foreach.index + 1 != $identity.getLinks().size())$link.getNativeIdentity(),#else$link.getNativeIdentity()#end#end"
},
"type": "static"
}
The code:
#foreach($link in $identity.getLinksByAppIdOrName(\"2c918088814e6a610181686b56977fa8\",null)) ## Pull accounts with the app id = 2c918088814e6a610181686b56977fa8
#if($foreach.index + 1 != $identity.getLinks().size()) ## Use the index of the loop to determine if we are on the last result
$link.getNativeIdentity(), ## If we are not on the last result, return the comma
#else
$link.getNativeIdentity() ## If we are on the last result return the account name without the comma
#end
#end