Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

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

I want to move all blogposts from one space to another and set a label for each blogpost

I created a user macro which works to move all blogposts. But I am not able to add a label. The method createLabel(Label label) needs a value of the type Label, not a string. How to solve that?

## 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
## @param OriginSpace:title=Origin Space|type=spacekey|required=true|desc=Space
## @param TargetSpace:title=Target Space|type=spacekey|required=true|desc=Space
## @param Label:title=Label|type=string|required=false|desc=Label
#set($originSpace = $spaceManager.getSpace($paramOriginSpace) )
#set($targetSpace = $spaceManager.getSpace($paramTargetSpace) )
#set($labelManager = $action.getLabelManager() )
#set($blogPosts = $pageManager.getBlogPosts($originSpace, true) )
#if($req.getParameter("move") )
   #foreach($blogPost in $blogPosts)
     <li>move $blogPost to $targetSpace
       #if($paramLabel != "")
           ##set($label = $labelManager.createLabel($paramLabel) ) #* doesn't work, object Label is required: Label createLabel(Label label) *#
           ##$labelManager.addLabel($blogPost, $label) 
       #end
       $blogPost.setSpace($targetSpace)
       #if($blogPost.isInSpace($targetSpace)  )
          <span style="color:darkgreen"> moved ☑</span>
       #end
     </li>
   #end
#else
<h3>Move all blogposts from $originSpace to $targetSpace?</h3>
<form  method="get">
    <input type="submit" name="move" value="move all blogposts listed below">
</form>
<hr/>
   #foreach($blogPost in $blogPosts)
     <li>$blogPost (Labels:  $blogPost.getLabels() )</li>
   #end
#end

2 answers

1 accepted

0 votes
Answer accepted

There must be some way to do it on the back end, but it's just as easy to do it on the front end.  Here's how I would do it:

## 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
## @param OriginSpace:title=Origin Space|type=spacekey|required=true|desc=Space
## @param TargetSpace:title=Target Space|type=spacekey|required=true|desc=Space
## @param Label:title=Label|type=string|required=false|desc=Label
#set($originSpace = $spaceManager.getSpace($paramOriginSpace) )
#set($targetSpace = $spaceManager.getSpace($paramTargetSpace) )
#set($labelManager = $action.getLabelManager() )
#set($blogPosts = $pageManager.getBlogPosts($originSpace, true) )
#if($req.getParameter("move") )
   #foreach($blogPost in $blogPosts)
     <li>move $blogPost to $targetSpace
       #if($paramLabel != "")
           <script>
               jQuery.post(contextPath+'/json/addlabelactivity.action', {'entityIdString': '$blogPost.id', 'labelString': '$paramLabel', 'atl_token': jQuery('#atlassian-token').attr('content') });
           </script>
       #end
       $blogPost.setSpace($targetSpace)
       #if($blogPost.isInSpace($targetSpace)  )
          <span style="color:darkgreen"> moved ☑</span>
       #end
     </li>
   #end
#else
<h3>Move all blogposts from $originSpace to $targetSpace?</h3>
<form  method="get">
    <input type="submit" name="move" value="move all blogposts listed below">
</form>
<hr/>
   #foreach($blogPost in $blogPosts)
     <li>$blogPost (Labels:  $blogPost.getLabels() )</li>
   #end
#end

Stephen, many thanks, you made my day ;-)

This is awesome! thanks Stephen & Stefan! :)

This does not work for me when I use in the Confluence User Macros, I get same as nicolarault below. Outputs code and does not move all the blogs. Is there something that I am missing when creating the User Macro?

Hi, I'm a beginner in Macro

I tried this one and all I get in output is HTML code escaped.

Example :

200812.png 

What did I forgot ?

I tried all options in "Macro Body Processing"

 

Thank you
Nicolas
France

Suggest an answer

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

Announcing Team Calendars in Confluence Data Center

Hi Community! We're thrilled to share that Team Calendars for Confluence is now a built-in feature for Confluence Data Center releases 7.11 and beyond.  A long time favorite,  Team Cale...

82 views 0 3
Read article

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