Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to add labels to the current page in a self-written user makro?

stafff95
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
March 27, 2015

I searched a lot, but nothing worked. There are downloadable Makros who manage to add labels you type into them, but as they´re not open source I can´t get behind that magic, which of course works, as I tested. Using the REST Api didn´t work, using the labelManager and labelUtil also lead to nothing. But I am sure there´s a way to use the labelManager to do so, maybe with the function "addLabel(Labelable content, Label label)" but there I don´t know with what to fill the parameters, beacause I have no access to the current page and I don´t know how to create a new label.

Thanks for your help

2 answers

1 vote
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.
March 27, 2015

I've tried adding labels via user macro, and the easiest thing I've found is to use ajax and let Confluence take care of the rest of the details.  Here is a simple user macro that adds a label based on what you type into a text field.

## @noparams
<script>
var addLabel = function(label) {
    jQuery.post(contextPath + "/json/addlabelactivity.action", {"entityIdString": "$content.id", "labelString": label, "atl_token": jQuery("#atlassian-token").attr("content") }, function() {
        jQuery("#label-to-add").val("");
    });
}
</script>
<form class="aui" onsubmit="return false;">
  <input id="label-to-add" class="text">
  <button class="aui-button aui-button-subtle" onclick="addLabel(jQuery('#label-to-add').val());">
    <span class="aui-icon aui-icon-small aui-iconfont-add">Add </span>
  </button>
</form>
stafff95
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
March 27, 2015

thank you very much it works fine for me :)

Melissa C
Contributor
October 10, 2017

This is great!  Thanks for posting.  

Can I use a field in my macro example "Document Number" that populates the label for the page.  I'm pretty new to this so I'm no sure how to do that yet.  

I currently have my users populating a number of fields in a macro. I wanted to use the "Document Number" field to update the label of the page. 

what should I add to do this?

0 votes
Kevin Suter
Contributor
October 18, 2018

Thank you for this macro. It still works with Confluence 6.11.2.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events