In the following code I am trying to access a collection with a single member. The foreach works as described but I am unable to access items in the collection by index.
#set($customFields = $customFieldManager.getCustomFieldObjectsByName("Property"))
$customFields[0].name
#if(!$customFields.empty)
#foreach($customField in $customFields)
$customField.name
#end
#end
Prints
[Property][0].name
Property
What am I not understanding?
I got this to work by using the .get() method!
#set($customFields = $customFieldManager.getCustomFieldObjectsByName("Property"))
#set($propertyField = $customFields.get(0)) ## Can only be the "Property" field (or bust)
then to get the "property" field value I did this:
$issue.getCustomFieldValue($propertyField.id)
No more loops required!!!
Glad to see you worked it out just about fine.
In my experience this sort of matters can get (no pun intended) a bit tricky ;)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I'm no programmer so maybe there's some error in your code that I can't see (I have very limited programming capabilities and I usually learn as I need). Aside from that possibility, I had problems in the past using $customFieldManager.getCustomFieldObjectsByName( )
Maybe you could try:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It does return the expected custom field and it does contain the expected value if I use :
$customField.value
Of course this works only in the loop!
If use:
$customFields[0].value // I tried [1] as well
then that too doesn't work.
So at the moment to access an item in an array I seem forced to use a loop. Which means iterating through the loop until I reach the required index.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.