I have a user macro (developed by someone else who is no longer available to help debug) which worked in Confluence 6.13.7 but no longer works in 7.4. For context, I'm a Confluence administrator but do not understand Velocity in-depth.
I've determined where the issue is and probably what's happening, but I don't know how to fix it:
The above code is the offender: the third line uses the .getTime() method on $review and $valid to return the unix time of each date and compare them to finally return a number of milliseconds difference between the two ($diff).
This works fine in 6.13 but in 7.4 it appears that the .getTime() method no longer works on the $valid variable. I suspect that it's because the data type is wrong or something like that. Is it possible to somehow convert the data so I can apply the method to it?
I wrote a very basic macro just to output the contents to the screen for troubleshooting:
<h2>GetTime Method Applied</h2> <br>
As an example, this is the output that I get:
Tue Jun 30 10:31:02 CEST 2020
GetTime Method Applied
What's really strange is that when I created this same troubleshooting macro in 6.13, the output in the vanilla section for $valid *looks* the same format in both versions of confluence - e.g. *2020-06-30 09:29:37.283* but the data is obviously not the same type.
Any help appreciated!
In the end I found this post which describes the same issue I was having it looks like a change due to a security issue caused this unexpected behaviour. Atlassian are aware and apparently looking into a fix.
In the meantime, based on the answers given in the above post, I managed to create a workaround. The post above just wanted to check whether two dates match, whereas I needed to check the difference (i.e. <30 days and >365 days):
#set($modified = $content.lastModificationDate)
#set($review30 = $action.dateFormatter.calendar)
#set($review365 = $action.dateFormatter.calendar)
#if ($review30.getTime().compareTo($modified) < 1) Less than 30 days
#elseif ($review365.getTime().compareTo($modified) > -1) Greater than 365 days
This allows me to check $modified against $review30 and $review365 and output (1, 0, -1) depending on the result, and do something, in the above case simply print a message.
Hopefully this will be helpful to someone who comes across the same issue.
all public methods are accessible in velocity, just like java. check public methods with the following docu and see if your time method is still there:
context.put('class', new ClassTool());
or some trial and error with:
Hey there! New in town? Check out the new Confluence product guides! They are chock-full of helpful tips, tricks, and best practices to get you and your team started. Here’s a quick overview...
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