Live Input Macros

HTML and JavaScript

On this page:

  1. Getting the Page Variables
  2. Setting Page Variables
    1. Persistent
    2. Non-persistent, no feedback
    3. Non-persistent, with user feedback

Using Live Input Macros, it is possible to create integrated solutions and rich features using Live macros, JavaScript and possibly some HTML.

In order to take advantage of the JavaScript interface, it will be necessary to enable the HTML Macro in the Confluence Manage Apps section in the setup pages.

Similar to the REST API, the JavaScript API requires the macros to define a Page Variable as this will be used as the key to the JavaScript API.

Getting the Page Variables

Using JavaScript, the following map is available, and initialized with all the Page Variables on page load using the REST API.

window.limPageVariables

To retrieve the value of a Page Variable, call the get() method.

For example:

To retrieve the page variable called “UserName”, use window.limPageVariables.get(‘UserName’);

The Page Variables may take up to 1 second to populate after the page loads. It is recommended to use a Timeout to test when they are available if js code is required to be executed without user input (i.e on page load)

function startFromPageLoad()

{

    if(window.limPageVariables.size == 0)

    {

        // wait for limPageVariables to be loaded

        setTimeout(startFromPageLoad, 800);

        return;

    }

    // access the Page Variables now....

    var s = window.limPageVariables.get("s");

    // do further processing

}

Setting Page Variables

Depending on what is required to be set, there are a few choices in setting Page Variables.

  • Persistent
  • Non-persistent, no feedback
  • Non-persistent with user feedback

Persistent

In order to make changes to the Page Variable data, and make it persistent, i.e. save the data on the server, use the REST API.

Non-persistent, no feedback

To make local changes in the browser for further processing, without needing to save the data or show the user, use the limPageVariables map to set() the new value.

For example:

data = window.limPageVariables.get('UserName');

data.value = "John Smith";

window.limPageVariables.set('UserName', data);

Non-persistent, with user feedback

Using a combination of the limPageVariables map set() function and JavaScript selectors, it is possible to update the HTML input control so that if changes are made on the page (and not persistent) then the user will see the change.

For example:

data = window.limPageVariables.get('UserName');

$('#'+data.id - This website is for sale! - data Resources and Information. ).val("John Smith");