Forums

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

Get nested user macro data

Dominic Lagger
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.
May 22, 2019

Hi all,

I'm writing an user macro (mymacro) which is using another macro (pocketquery)

Pocketquery is a macro, which gets data via rest services from another server. In my case, the macro gets different user names and values from another server.

My code looks like this:

#set ( $myStatement ='$action.getHelper().renderConfluenceMacro("{PocketQuery:name=All_Data|parameters=Service_ID\=1340}") ')
#set ($snowInfos = "#evaluate( $myStatement )")

$snowInfos

In the String "$snowInfos" is now the HTML/Javascript Code, which is rendered dynamically when I open the page. But I would like to use the rendred data from pocketquery for further calculations. 

Does anyone can help me here? 

 

 

1 answer

1 accepted

2 votes
Answer accepted
Felix Grund (Scandio)
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.
May 22, 2019

Hi @Dominic Lagger ,

Can you show me what $snowInfos contains exactly? Is this already the result from your REST endpoint?

Best, Felix

Dominic Lagger
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.
May 22, 2019

Hi Felix

in the $snowInfos is this html code: 

<div class="pocketquery-view-container" data-query="All_Data"> <meta name="ajs-pq-All_Data-allowgetparams" content="false"></meta> <script id="pocketquery-view-tmp-script">PocketQuery.chartJson("All_Data", "{\"rows\":[{\"c\":[{\"v\":\"1340\"}]},{\"c\":[{\"v\":\"\"}]},{\"c\":[{\"v\":\"Server-Care\"}]},{\"c\":[{\"v\":\"Ian Ott\"}]},{\"c\":[{\"v\":\"Rainer Helg\"}]},{\"c\":[{\"v\":\"Operativ\"}]}],\"cols\":[{\"id\":\"0\",\"label\":\"0\",\"type\":\"number\"},{\"id\":\"1\",\"label\":\"1\",\"type\":\"string\"},{\"id\":\"2\",\"label\":\"2\",\"type\":\"string\"},{\"id\":\"3\",\"label\":\"3\",\"type\":\"string\"},{\"id\":\"4\",\"label\":\"4\",\"type\":\"string\"},{\"id\":\"5\",\"label\":\"5\",\"type\":\"string\"}]}");
PocketQuery.queryJson("All_Data", "[{\"0\":\"1340\"},{\"1\":\"\"},{\"2\":\"Server-Care\"},{\"3\":\"Ian Ott\"},{\"4\":\"Rainer Helg\"},{\"5\":\"Operativ\"}]");
PocketQuery.queryColumns("All_Data", "[\"0\",\"1\",\"2\",\"3\",\"4\",\"5\"]");
jQuery('#pocketquery-view-tmp-script').remove();
</script> <div class="pocketquery-result" id="pocketquery-result-1558557128901"> <script id="pocketquery-view-tmp-script"> AJS.trigger('pocketquery.before.render.result', {
container: jQuery("#pocketquery-result-1558557128901")
}

);
jQuery('#pocketquery-view-tmp-script').remove();
</script> '1340',
'',
'Server-Care',
'Name',
'Dominic Lagger',
'Operativ',
<script id="pocketquery-view-tmp-script"> AJS.trigger('pocketquery.after.render.result', {
container: jQuery("#pocketquery-result-1558557128901")
}

);
jQuery('#pocketquery-view-tmp-script').remove();
</script> </div> </div>

This will rendering into this: 

'1340', '', 'Server-Care', 'Name, 'Dominic Lagger', 'Operativ', 

What I want is a String array with these information, so I could say:

$string.get(4) = "Dominic Lagger"

Hope this helps for further analysis

Regards, Dominic

Sven Schatter _Lively Apps_
Atlassian Partner
May 23, 2019

Hmmm.... I can't think of an easy and simple way to do this in the user macro.

Is there a reason why you need to use a user macro for the "further calculations"? Also, what exactly do you mean by further calculations?

I think there's a good chance that you want to do these in the template of your query instead where you can access all of the PocketQuery Velocity API. Doing that via a user macro just seems like the more complicated way. :)

Dominic Lagger
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.
May 23, 2019

Yes, it seems strange. I try to explain, why I want to do this in the user macro.
I have a table with 14 rows. 6 of this rows will be filled from the REST call of PocketQuery.
The other 8 rows have to be filled in manually. The order is pretty important, and it has to be 1 table, because it is a page property table.
In the picture below you see:

  • the yellow marked are information, which I get from Pocketquery REST.
  • the red has to be filled in manually.

pocketquery.png

Now, as it is, I need to make 6 REST Calls to the other server.
The funny part, I make 6 times the SAME REST Call... Just display an another value...
And for our not so smart users, I don't want them they has to use 6 macros.
So my thought was "Hey, make an easy user makro, you just add the parameter once and get all data, save the data and place it in the table." The manually values (the red ones) are parameters and has to filled in the edit macro view

Do you know what I mean?
Was it fairly understandable?

Like • Sven Schatter _Lively Apps_ likes this
Sven Schatter _Lively Apps_
Atlassian Partner
May 24, 2019 edited

Okay, now everything makes sense. Good explanation! :)

So... the obvious one here would be to enable caching on your query if you haven't done so already. This always reduces stress on your data source, so it's almost always a good idea. But of course the result of your query is dependent on a parameter, so caching will only really help if the user reloads the page - not so much for your original problem.

Hmmm... So, solving this problem via a user macro might seem like a good idea at first but is actually really really hard. Velocity is a nice templating language but is extremely inconvenient to use for advanced logic (like parsing strings). Since you can't use the PocketQuery API in user macros (yet) you should find another way to do this.

I'm pretty sure I have a good idea for a workaround. Although it will require some testing on your side and also some back and forth and further explanations. For this reason it would probably be good if you raised a ticket at our ServiceDesk where we can discuss the details and also speak german. :)

If anyone reading this thread has a similiar problem - don't hesitate to raise a ticket as well. That's the easiest and quickest way for us to help you!

Like • 2 people like this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events