Forums

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

Export of user macro values not workling when using javascript

thorsten_schmidt June 1, 2018

Hi,

I'm just getting started to create user macros for confluence so I hope this is not a to silly question.

I created an user macro which simply searches for some text on it's confluence page and depending on the search result creates an output.

Simplified it looks like this:

<span id=(resultDate+$content.id)></span>

<script>
$(document).ready(function() {

    var dateElement = document.getElementById("(resultDate+" + $content.id+ ")");
        var dateResult = "Date result text";

    $(dateElement).html(dateResult);

});
</script>

The macro works as expected but when I try to export the page as pdf or word my result is not included in the export.

As far as I searched the forum I guess that exporting is done on the server side and the javascript is done on the client side so that my javascript is not executed when exporting.

How can I achieve that my result is also included in the export-files?

Best regards,
Thorsten

4 answers

2 accepted

0 votes
Answer accepted
Nic Brough -Adaptavist-
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.
June 4, 2018

Using javascript in Atlassian applications is always a pain, and generally the second worst way to do anything with them.

User macros are a clumsy way to do javascript too - why not write the macro to do the work properly, as they're designed to do?

thorsten_schmidt June 7, 2018

Looks like writing a macro is the only clean possibility.

Danyal Iqbal
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.
June 12, 2018

the second worst way

Wondering about the first worst way.

0 votes
Answer accepted
Davin Studer
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.
June 1, 2018

You are correct that the PDF and Word export is server side. You could however, run your user macro and the print to PDF. That happens client side and thus you DOM changes made via JavaScript would be caught.

thorsten_schmidt June 4, 2018

Hmm I already feared that. So there is no other possibility?

0 votes
thorsten_schmidt June 7, 2018

Up to now the only possible solution apart from using the printing functionality of the browser would be to write a "real" macro and not to use the user macros.

As I'm new to the Atlassian Community: what should I do with my answer? Accept a solution, leave it open?

Davin Studer
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.
June 7, 2018

I would accept a solution(s) if the question is answered ... even if it's not the answer you were hoping for. Unfortunately, sometimes the correct answer is "It can't be done the way you want".

0 votes
Danyal Iqbal
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.
June 1, 2018

where is the execute method? It makes more sense to pass a json to js from the execute method.

thorsten_schmidt June 4, 2018

I thought that there is no need for an execute method. The script is automatically executed after the page is loaded

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events