Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How can I add a custom property to an attachment?

Bill Bailey
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 15, 2018

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.

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events