Can inline comments be converted to page comments?
Asked by Inayat Nahvi:

Hi,

We have a confluence page that has several inline comments (around 15). Is there a mechanism to convert them all to page comments? And retain the comment author and dates?

Thanks.


Answers:
author: Andrii Maliuta
body: Hello [@Inayat Nahvi](/t5/user/viewprofilepage/user-id/743883) ,

Yes, this can be possible with Confluence Java API. You just need to define what data to save (line highlighted content for inline comment) if it should be saved in the body of the page bottom comment or not.

You can use:

1. ScriptRunner (if installed)
2. Create custom addon
3. Use REST API client and Confluence REST API (a little more hand work)

Smth like:

```
PageManager pageManager = ComponentLocator.getComponent(PageManager.class);
CommentManager commentManager = ComponentLocator.getComponent(CommentManager.class);
Page page = pageManager.getPage(111);
page.getComments().forEach(comment -> {
if (comment.isInlineComment()) {
comment.setInlineComment(false);
 comment.setContainer(page);
 commentManager.saveContentEntity(comment, DefaultSaveContext.SUPPRESS_NOTIFICATIONS);
 }
});
```

comments: author: Inayat Nahvi
body: Thanks [@Andrii Maliuta](/t5/user/viewprofilepage/user-id/484201) . We have Scriptrunner for Jira, but not Confluence. Do you think this might be possible with the [Confluence CLI plugin?](https://marketplace.atlassian.com/apps/284/confluence-command-line-interface-cli?hosting=server&tab=overview)


author: Darryl Lee
body: Also, I'm not ScriptRunner expert, but wouldn't this lose the original comment author and timestamp?

(Like, does the comment function allow you to override author/timestamp? Seems like you'd need admin rights for that, if it's possible at all.)


author: Andrii Maliuta
body: [@Darryl Lee](/t5/user/viewprofilepage/user-id/1365322) !

Thanks for the comment :)

\>\> *but wouldn't this lose the original comment author and timestamp*

\[AM\] here just 2 props are updaetd and the same comment with all the previous data is passed to **saveContentEntity** method. But yes, it is always needs to be TESTED first :) There are other methods/approaches to try.

\>\> *(Like, does the comment function allow you to override author/timestamp? Seems like you'd need admin rights for that, if it's possible at all.)*

\[AM\] Yes, if you are comment author or space admin where comments are located or Confluence admin - it should be work.


author: Andrii Maliuta
body: [@Inayat Nahvi](/t5/user/viewprofilepage/user-id/743883) , as for the CLI app:

It can be possible to

1. create comments from inline ones:

2. remove the original ones

like:

```
--action runFromCommentList --space "SPACE_KEY" --title "PAGE_TITLE" \
    --common "-a addComment --space "SPACE_KEY" --title "PAGE_TITLE" --comment @commentId@"
```

this is just a sketch :)

If highly required, I can try to practice to find the solution :)


author: Darryl Lee
body: So full disclosure, I work with [@Inayat Nahvi](/t5/user/viewprofilepage/user-id/743883), and after he posted this question, I found this ticket [CONFSERVER-38240](https://jira.atlassian.com/browse/CONFSERVER-38240) which included a very clever [Bookmarklet](https://jira.atlassian.com/browse/CONFSERVER-38240?focusedCommentId=791113&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-791113) (Javascript snippet that works as a Bookmark) created by [@Andrei Mitin](/t5/user/viewprofilepage/user-id/3718156)

With the click of a button in the browser, you can have inline comments show up at the bottom of the page as if they were regular comments. Even more interestingly, [@Immanuel Comer](/t5/user/viewprofilepage/user-id/4919297) had the idea to add this to **Custom HTML** in the**End of Body** section (surrounded by \<script\> tags), so this would show for every page. This is probably too much for our use case. Would be nice if I could do this on a per space basis.

I made a tweak to the Javascript to include the timestamp (which sadly only shows a **date** after I guess 24 hours?), and I'm actually pretty happy with how it turned out. Not sure if it we'll actually implement it though, as I'm sure people will complain about double-comments.

![Screen Shot 2023-04-27 at 12.50.36 PM.png](https://community.atlassian.com/t5/image/serverpage/image-id/254316i6E4EBE92039F0A3C/image-size/large?v=v2&px=999 "Screen Shot 2023-04-27 at 12.50.36 PM.png")

comments: author: Darryl Lee
body: Updated Javascript to include timestamps:

```
javascript&colon;$('[class^=icg-]').remove();
$('[class*=icgc-]').each(function(){
$(this).removeClass('icgc-resolved').removeClass('icgc-unresolved');
});

$(document.head).append('<style class="icg-style">' +
'.icgc-resolved { -webkit-print-color-adjust: exact; background-color: #afa; }' +
'.icgc-unresolved { -webkit-print-color-adjust: exact; background-color: #ffa; }' +
'</style>');
$.get( '/rest/inlinecomments/1.0/comments?containerId=' + $('[name=treePageId]').val() + '&_=' + new Date().getTime(), function (data, textStatus, xhr) {
$('#comments-section').append('<h1 class="icg-h" style="page-break-before: always">Inline comments</h1>');
$('#comments-section').append(data.map(function(comment, index) {
var resolved = comment.resolveProperties.resolved === true;
return '<div class="icg-c" id="icg-c-' + comment.markerRef + '" data-commentid="' + comment.id + '" data-index="' + (1 + index) +
'" style="margin-top: 20px; padding-top: 10px; border-top: solid 1px #ddd">' +
'<a href="#icg-s-' + comment.markerRef + '"><b class="' + ( resolved ? 'icgc-resolved' : 'icgc-unresolved' ) + '">' + (1 + index) + '. ' + ( resolved ? '[resolved] ' : '' ) + comment.authorDisplayName + ' (' + comment.lastModificationDate + ')' + '</b></a>:<br/>' + comment.body + '</div>';
}).join(''));

$('.icg-c').each(function(){
var $cdiv = $(this);
var commentId = $cdiv.data('commentid');
$.get( '/rest/inlinecomments/1.0/comments/' + commentId + '/replies?_=' + new Date().getTime(), function (data, textStatus, xhr) {
$cdiv.after(
data.map(function(comment, index) {
return '<div class="icg-c-r" style="margin-top: 10px; border-top: solid 1px #eee; margin-left: 30px; padding-top: 10px"><b>' +
comment.authorDisplayName + ' (' + comment.lastModificationDate + ')' + '</b></a>:<br/>' + comment.body + '</div>';
}).join(''));
});
});

$('.inline-comment-marker').each(function(){
var $this = $(this);
var ref = $this.data('ref');
$this.attr('id', 'icg-s-' + ref).addClass( $this.hasClass('valid') ? 'icgc-unresolved' : 'icgc-resolved' );
$this.after($('<sup class="icg-f"><a href="#icg-c-' + ref + '">[' + $('#icg-c-' + ref).data('index') + ']</a></sup><span> </span>'));
});
});
(function(){})();
```


author: Andrii Maliuta
body: Hi [@Darryl Lee](/t5/user/viewprofilepage/user-id/1365322) ,

Thank you for the update. Yes, it is possible to change the look as you want with AJS/JS, though it influences the UI . Please note that AJS/AUI can change when new major versions are released and you will have to adapt the code - <https://aui.atlassian.com/aui/latest/docs/upgrade-guide.html>

There is this app that gathers comments in UI menu and in macro s table and then you can export them, but it is **PAID** - <https://marketplace.atlassian.com/apps/1219786>.

I suppose such gathering of comments can be done in many ways and it depends on how it will be maintained :) We usually do this in custom apps that have in companies internally.


Tags: confluence-server

server