It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Getting and setting content properties via user macro not working anymore

Hey community,

maybe someone out there can help me out on this one. I've written a small user macro to set certain content properties in order to get/display them (via a different user macro) somewhere on a Confluence page.

The whole setup worked like a charm until I upgraded to the latest Confluence version and installed a reverse proxy with SSL before the Tomcat. The whole system is still working flawlessly (application links to JIRA/Bitbucket, other macros etc.)... but something seems to have broken the macro.

This is the macro itself (don't mind the "tollgate_step macro", which is simply some fancy CSS stuff):

## Macro title: SWTollGate
## Macro has a body: N
## Body processing:
## Output: Selected output option
##
## Developed by: Dominic Finke
## Date created: 06/03/2018
## Installed by: Dominic Finke

## @param swstep:title=SW TG Step|type=enum|enumValues=TG1,TG2,TG3,TG4,TG5|default=TG1|desc=SW TollGate Step
## @param swstepduedate:title=SW Step Due Date|type=date|default=|desc=Due Date Of This SW TollGate Step - Format dd-mm-yyyy

#set($returnstatus="InProgress")
#foreach ($mflabel in $content.getLabels())
#if($mflabel.toString()=="$paramswstep.toLowerCase()")
#set($returnstatus="Done")
#end
#end
<ac:structured-macro ac:macro-id="663211e4-2bb1-40fa-afff-55b919fc1b47" ac:name="tollgate_step" ac:schema-version="1">
<ac:parameter ac:name="title">$paramswstep</ac:parameter>
<ac:parameter ac:name="status">$returnstatus</ac:parameter>
</ac:structured-macro>
<p><b>Due: $paramswstepduedate</b></p>

#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'))

$contentPropertyManager.setStringProperty($content, "dueDate$paramswstep", "$paramswstepduedate")

When rendering on a page, it should look / was looking like this:

2020-02-06_13h46_51.png

But now it looks like this:

2020-02-06_13h47_59.png

Something is clearly messed up and I can't figure out what it is. Any ideas? 

 

Cheers,

Dom

1 answer

1 accepted

0 votes
Answer accepted

Okay... almost forgot this. Just in case someone else has an issue like that - I already stumbled over the solution.

Turns out that Atlassian made it way more easy to get a hold of the properties in newer Confluence versions. 

This:

#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'))

$contentPropertyManager.setStringProperty($content, "dueDate$paramswstep", "$paramswstepduedate")

can now be achieved by this: 

$content.getProperties().setStringProperty("dueDate$paramswstep", "$paramswstepduedate")

After removing the gazillion lines and put in this one-liner, everything is working normal again. Awesome! :D

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Posted in Confluence

Lessons and Learnings: Six Months of Working Remote [Discussion]

Hey there, folks! For most of us, the past six months- yes, you read that right- have been a journey. More people than ever before have pivoted to working remotely, and navigating being on-scre...

7,545 views 6 6
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you