Hi we have a user macro named "UPDATE HISTROY". This has been hadr coded for only particular space only. So i need guidance in this script so that it will be used for all spaces in confluence. Do kindly let me know if any body can help with this. Thanks in advance. Here is the script what i have
## @noparams
#set ( $descendantPages = $pageManager.getPage("NTGSDHSI","Project Status").getChildren() )
#set ( $compareDate = $action.dateFormatter.getCalendar() )
$compareDate.setTime($content.getCurrentDate())
$compareDate.add(6, -7)
<table>
<tr>
<th>Status Page</th>
<th>Last Modified By</th>
<th>Last Modified Date</th>
<th>Modified in last seven days?</th>
</tr>
#foreach ( $page in $descendantPages )
<tr>
<td><a href="$
{req.contextPath}
$childPage.urlPath"> $page.title </a></td>
<td> $page.lastModifier.name </td>
<td> $action.dateFormatter.format($page.lastModificationDate) </td>
<td>
#set ($pageDate = $action.dateFormatter.getCalendar())
$pageDate.setTime($page.getLastModificationDate())
#if ( $pageDate.before($compareDate) )
<span class="aui-lozenge aui-lozenge-error">NO</span>
#else
<span class="aui-lozenge aui-lozenge-success">YES</span>
#end
</td>
</tr>
#end
</table>
Ok, I think I found the solution. But be aware, this solution uses methods which are depricated in version 7.3. This means, they might work for longer (worked with 7.13), but atlassian can always delete this methods.
What I did:
Hope this is what you want
## Macro title: My Macro
## Macro has a body: Y or N
## Body processing: Selected body processing option
## Output: Selected output option
##
## Developed by: My Name
## Date created: dd/mm/yyyy
## Installed by: My Name
## This is an example macro
## @noparams
#set( $spaceManager = $action.getSpaceManager())
#set( $actualSpace = $spaceManager.getSpace($space.key))
#set ($spaces = $spaceManager.getAllSpaces())
#set( $allSpaceKeys=[] )
#foreach ($space in $spaces)
#set ($key = $space.getKey())
#set( $dummy = $allSpaceKeys.add($key) )
#end
#set( $descendantPages=[] )
#foreach ($spacekey in $allSpaceKeys)
#set ( $dumm = $descendantPages.add($pageManager.getPage($spacekey,"Project Status").getChildren() ))
#end
#set ( $compareDate = $action.dateFormatter.getCalendar() )
$compareDate.setTime($content.getCurrentDate())
$compareDate.add(6, -7)
<table>
<tr>
<th>Status Page</th>
<th>Last Modified By</th>
<th>Last Modified Date</th>
<th>Modified in last seven days?</th>
</tr>
#foreach ($descendants in $descendantPages)
#foreach ( $page in $descendants )
<tr>
<td><a href="$
{req.contextPath}$childPage.urlPath"> $page.title </a></td>
<td> $page.lastModifier.name </td>
<td> $action.dateFormatter.format($page.lastModificationDate) </td>
<td>
#set ($pageDate = $action.dateFormatter.getCalendar())
$pageDate.setTime($page.getLastModificationDate())
#if ( $pageDate.before($compareDate) )
<span class="aui-lozenge aui-lozenge-error">NO</span>
#else
<span class="aui-lozenge aui-lozenge-success">YES</span>
#end
</td>
</tr>
#end
#end
</table>
On almost the first line, you go and get the page with the Spacekey NTGSDHSI and the title "Project Status". (see documentation)
#set ( $descendantPages = $pageManager.getPage("NTGSDHSI","Project Status").getChildren())
So it will always get these pages, doesn't matter where you put your macro.
Regards, Dominic
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Dominic Lagger ,
I think you have wrongly understood my problem. Let me explain you clearly. This update history macro is hard coded for only particular space(like mentioned NTGSDHSI). Now we need to modify the code so that it works for all the spaces present in confluence. So final conclusion is that update history macro must be used for all spaces not only for a single space. And many thanks for the reply. Awaiting for your response.
Regards,
Aravind
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I understand you correctly, I just wanted to point out, why it's just working for that space. Because you hard code the key in your marco.
If you want to work it for all spaces, then perhaps this could help you.
#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( $pageManager=$containerContext.getComponent('pageManager') )
#set( $page = $pageManager.getPage($content.getId()) )
This give you the actual page, where the macro is sitting. From there, you should be able to do the rest.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Dominic Lagger ,
Really sorry for that i misunderstood you. Thanks for the code. I am testing it out. Will tell you once if it is an successful one or not. Thankyou so much for the code.
Thanks,
Aravind
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Dominic Lagger ,
I tried this out but it's not working as expected.Its not giving us the update history of all the spaces or in particular space.Can you briefly modify the code what I have provided you and modify that to work for all spaces? If it's possible try that once.Or a big thanks for helping me out in this.
Regards,
Aravind
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I'm not sure what is your goal. What should this macro do?
And also, what do you mean by: "update history of all the spaces or in particular space". You can't have a space in a space. Do you mean pages?
And last question, what history do you want to update? The whole user macro just display a table, and do not update anything, it never did.
Thanks and Regards, Dominic
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Dominic Lagger ,
When you see the code it gives us a table present in project NTGSDHI. This means that it is hardcoded for particular space only right. Now i want a modification to the code that works for the remaining spaces as well not for particular space NTGSDHI. Can we do this is what my question is.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.