Forums

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

Importing In Confluence - add Label programmatically via macro

Melissa C
Contributor
June 18, 2018

Hello!

Looking for some guidance! 

I recently had to change my teams process to accommodate Word Documents.  We were using Scroll Office to export Confluence Pages into Word Documents. Unfortunately the add on has a few flaws that won't be fixed any time soon. 

My Team will now import their Word Documents into Confluence each time they want to electronically publish a document.   In the import we need to have a few labels that will kick off a workflow.   

Instead of having my users manually enter the Label I want the labels to be added automatically or have the macro below add the label "behind the scene". 

We currently have a macro (this is is a snippet of the actual one) that asks the user to input a unique document number the macro takes that Macro and adds it as a label.   I want to at minimum add code to this macro that adds two labels "docparent" and "controlled-document". 

 

 

## @Param
## @Param DocNum:title=Enter Document ID # REQUIRED |type=string|required=false|desc=Test

<table>
<tr>
<td>Document ID # = $paramDocNum</td>
</tr>
</table>

###Script adds Document number to Parent Page, Child Pages and Descendants
#if ( $paramDocNum )
#set ( $hasLabel = false )
#foreach ( $label in $content.getLabels() )
#if ( $label == $paramDocNum )
#set ( $hasLabel = true )
#end
#end

#if ( !$hasLabel )
<script>
AJS.toInit(function() {
jQuery.post(contextPath + "/json/addlabelactivity.action", {
"entityIdString": "$content.id",
"labelString": "$paramDocNum",
"atl_token": jQuery("#atlassian-token").attr("content")
});
});
</script>
#end

#set($childpages = $content.getDescendants())
#foreach($page in $childpages)
#set ( $hasLabel = false )
#foreach ( $label in $content.getLabels() )
#if ( $label == $paramDocNum )
#set ( $hasLabel = true )
#end
#end

#if ( !$hasLabel )
<script>
AJS.toInit(function() {
jQuery.post(contextPath + "/json/addlabelactivity.action", {
"entityIdString": "$page.id",
"labelString": "$paramDocNum",
"atl_token": jQuery("#atlassian-token").attr("content")
});
});
</script>
#end
#end
#end

 

1 answer

2 votes
Melissa C
Contributor
June 18, 2018

Looks like I answered my Own Question!!!

I added the following and worked like a charm

#if ( !$hasLabel )
<script>
AJS.toInit(function() {
jQuery.post(contextPath + "/json/addlabelactivity.action", {
"entityIdString": "$content.id",
"labelString": "docparent, controlled-document",
"atl_token": jQuery("#atlassian-token").attr("content")
});
});
</script>
#end

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events