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

Remove labels on current page in Confluence

lazy boy August 11, 2015

Hi everyone,

I'm looking for a user macro that removes the labels from the current Confluence page.

Ideally, I would like a 'button' and when clicked will remove the labels.

Is this possible?

Thanks!

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

2 votes
Answer accepted
Stephen Deutsch
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.
August 12, 2015

This is a bit quick and dirty, but it'll do:

## @noparams
#if($permissionHelper.canEdit($userAccessor.getUserIfAvailable($req.getRemoteUser()),$content))
  <button class="aui-button" onclick="removeLabels()">Remove all labels</button>
  <script>
    var removeLabels = function() {
      jQuery.ajax({
        url: contextPath + "/rest/api/content/" + $content.id + "?expand=metadata.labels",
        success: function(response) {
          jQuery(response.metadata.labels.results).each(function() {
            jQuery.post(contextPath+'/json/removelabelactivity.action', {'entityIdString': '$content.id', 'labelIdString': this.name, 'atl_token': jQuery('#atlassian-token').attr('content') });
          });
        }
      });
      jQuery("li.aui-label").remove();
      jQuery("ul.label-list-right").prepend('<li class="no-labels-message">No labels</li>');
      alert("All labels removed.");
    }
  </script>
#end

EDIT: Oops, forgot to remove the hardcoded pageId smile

lazy boy August 17, 2015

Thank you Stephen! Just what I needed.

0 votes
Bob Swift OSS (Bob Swift Atlassian Apps)
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.
August 12, 2015

For the button part of this, you can use the Run macro with user macro as the body. 

For the user macro part, I am not sure. Maybe this question might help: https://answers.atlassian.com/questions/107652. If that doesn't work out, then you can always construct a small script using Scripting for Confluence

TAGS
AUG Leaders

Atlassian Community Events