First, a disclaimer. I know enough Velocity and Java to be dangerous, but I do a mean copy and paste. ;-)
I am building a user macro that will retrieve a list of attachments (user documents), parsing the document number from the file name. I need to be able to sort the listing via this doc number.
My first thought was to just create a a customer property "guideno", using the following (I subbed a static "Test" at this point):
#set ($containerManagerClass=$content.class.forName('com.atlassian.spring.container.ContainerManager'))
#set ($getInstanceMethod=$containerManagerClass.getDeclaredMethod('getInstance',null))
#set ($containerManager=$getInstanceMethod.invoke(null,null))
#set ($containerContext=$containerManager.containerContext)
#set ($contentPropertyManager=$containerContext.getComponent('contentPropertyManager'))
#set ($attachmentsList = $content.getLatestVersionsOfAttachments())
#if ($attachmentsList.size() > 0)
#foreach( $attachment in $attachmentsList )
[code to parse the guideno]
$contentPropertyManager.setStringProperty($attachment, "guideno", "Test")
<p>$attachment.guideno</p>
[More code]
#end
#end
#end
I get no errors on rendering, but it is only returning:
$attachment.guideno
I am hoping people smarter than me can help.