Deprecation of $content.getLabelUtil()
Asked by Normann P_ Nielsen _Netic_:

My Macro:

## @noparams

\<div id="related-content"\>

\<script language=javascript\>

function toogle(divname) {  
if (document.getElementById(divname).style.display != "block") { document.getElementById(divname).style.display = "block"; }  
else { document.getElementById(divname).style.display = "none"; }  
}  
\</script\>

#if($content.getIdAsString()!='4161541')  
#set($wiki="")  
#set($globalHelper=$action.getHelper())  
#if($content) ## i. e. we render a normal page  
#set($renderer=$globalHelper.getWikiStyleRenderer())  
#set($context=$content.toPageContext())  
#set($labelList=$content.getGlobalLabels($action.getRemoteUser()))  
#if($labelList.size() \> 0)  
#set($labelUtil=$content.getLabelUtil())  
#set($labels=$labelUtil.convertToDelimitedString($labelList))  
#set($labels="'"+$labels+"'")  
#set($labels=$labels.replace(" ","','"))  
\<h1\>\<a href="javascript\&colon;;" onclick="toogle('rcontent');"\>Sider med lignende indhold\</a\>\</h1\>  
\<br\>  
\<div id="rcontent" name="rcontent" style="display:block;"\>  
\<ac:structured-macro ac:macro-id="e5bbc54f-287e-447c-9e9e-f84af88ad353" ac:name="contentbylabel" ac:schema-version="2"\>  
\<ac:parameter ac:name="showLabels"\>false\</ac:parameter\>  
\<ac:parameter ac:name="cql"\>label in ($labels) AND label != "noshow"\</ac:parameter\>  
\</ac:structured-macro\>  
\</div\>  
#end  
#end  
#end  
\</div\>

Is not working in C7, seems $content.getLabelUtil() is deprecated.... <https://confluence.atlassian.com/doc/deprecated-code-paths-removed-in-7-0-967879993.html>

Ok, what do I do? Ad get whats possible with $content ? All I find is C6.6 related


Answers:
author: Diego
body: Hello, [@Normann P_ Nielsen _Netic_](/t5/user/viewprofilepage/user-id/664692) !

I understand that is can be ++*quite troubling*++ when something is deprecated or completely removed from an array of tools that we are accustomed to using.

The ++*content.getLabelUtil() method has been deprecated*++ in a previous version of Confluence. ++*Confluence 5.2*++, to be more precise. Here you can check this information:
> * ++**[\[Confluence Server\] Confluence 5.4.2 API](https://docs.atlassian.com/atlassian-confluence/5.4.2/com/atlassian/confluence/core/AbstractLabelableEntityObject.html#getLabelUtil())**++

Here is a screenshot of that page:
> ![Anota??o 2019-10-28 171136.jpg](https://community.atlassian.com/t5/image/serverpage/image-id/70871iD57284E5A3D8A059/image-size/large?v=v2&px=999 "Anota??o 2019-10-28 171136.jpg")

According to the deprecation notice, we should ++*start using LabelUtil directly*++. Here is a link to it:
> * [++**\[Confluence Server\] \[Confluence 7.0.2 API\] Class LabelUtil**++](https://docs.atlassian.com/ConfluenceServer/javadoc/7.0.2/)

If you need further assistance with developing questions, you can reach to our Developer Community, Normann. Here, take a look!
> * **++[\[Atlassian Developer\] Community](https://community.developer.atlassian.com/)++**

Let us hear from you!

comments: author: Normann P_ Nielsen _Netic_
body: As in: #set($labels=$content.LabelUtil().convertToDelimitedString($labelList)) ?

That does not work ...


author: Federico Vecchiarelli
body: [@Normann P_ Nielsen _Netic_](/t5/user/viewprofilepage/user-id/664692)were you able to figure out how to properly access the class LabelUtil?


author: Normann P_ Nielsen _Netic_
body: [@Federico Vecchiarelli](/t5/user/viewprofilepage/user-id/4139726)

Long time ago - my current code is:

## @noparams

\<div id="related-content"\>

\<script language=javascript\>

function toogle(divname) {  
if (document.getElementById(divname).style.display != "block") { document.getElementById(divname).style.display = "block"; }  
else { document.getElementById(divname).style.display = "none"; }  
}  
\</script\>

#if($content.getIdAsString()!='4161541')  
#set($wiki="")  
#set($globalHelper=$action.getHelper())  
#if($content) ## i. e. we render a normal page  
#set($renderer=$globalHelper.getWikiStyleRenderer())  
#set($context=$content.toPageContext())  
#set($labelList=$content.getGlobalLabels($action.getRemoteUser()))  
#if($labelList.size() \> 0)  
#set($labels="")  
#foreach( $label in $labelList )  
#if($labels == '')  
#set($labels="'"+$label+"'")  
#else  
#set($labels=$labels+","+"'"+$label+"'")  
#end  
#end  
#set($labels=$labels.replace(" ","','"))  
\<h1\>\<a href="javascript\&colon;;" onclick="toogle('rcontent');"\>Sider med lignende indhold\</a\>\</h1\>  
\<br\>  
\<div id="rcontent" name="rcontent" style="display:block;"\>  
\<ac:structured-macro ac:macro-id="e5bbc54f-287e-447c-9e9e-f84af88ad353" ac:name="contentbylabel" ac:schema-version="2"\>  
\<ac:parameter ac:name="showLabels"\>false\</ac:parameter\>  
\<ac:parameter ac:name="cql"\>label in ($labels) AND label != "noshow"\</ac:parameter\>  
\</ac:structured-macro\>  
\</div\>  
#end  
#end  
#end  
\</div\>


author: Federico Vecchiarelli
body: Thanks [@Normann P_ Nielsen _Netic_](/t5/user/viewprofilepage/user-id/664692) . I was looking so hard at utilizing the actual method that totally overlooked the option to just iterate thru the list. What can I say, works for me!


Tags: confluence-server

server