Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

2. Use JavaScript Runner to get the data

Type Insert a JavaScript Runnet at the top of a new Confluence page and type following script in the body of JavaScript Runner the macro

Code Block
languagejs
titleInside JavaScript Runner
linenumberstrue
var yahooFinanceQuery='https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quote%20where%20symbol%20in%20(%22AAPL%22%2C%22GOOG%22%2C%22MSFT%22)&format=json&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=';
var yahooFinanceData=JSON.parse(http.get(yahooFinanceQuery));
var apple=yahooFinanceData.query.results.quote[0];
var google=yahooFinanceData.query.results.quote[1];
var microsoft=yahooFinanceData.query.results.quote[2];
context.set("google",google);
context.set("microsoft",microsoft);
context.set("apple",apple);

LINE DESCRIPTIONS:

1:    Created a variable to hold the url that calls the query

2: Call the url using http object get function and parse the result into a JSON object at the same time

3,4,5: Create variables to hold each symbol stock market data info

6,7,8: Use context object to attach those variable to this page context so other Javascript Runner macros in this page be able to access those

2. Use varibales attached to the context

Now we will create a table and inside each table cell we will insert a JavaScript Runner macro calling the property we need

Image Added

3. View the Dynamic Table

The table's data will be updated each time page loads, in this example the stock price per share will get updated

Image Added