[JavaScript] How To Work On JavaScript

This recipe shows how to use the Base64.js file in the report template.

Steps taken:

  1. Create a report template (Base64.rml).
  2. Add the following script into “Report Properties > On Render Begin”:importScript("/Elixir/ER_Cookbook/lib/Base64.js");
    function make_base_auth(user, password) {
    var tok = user + ‘:’ + password;
    var hash = Base64.encode(tok);
    return "Basic " + hash;
    }
  3. Add the following script into “Data Field (Type: Script)” in the report template Layout page:var url = “http://localhost:8080/data/ElixirSamples/DataSource/FruitSales.ds”;
    var auth = make_base_auth(“admin”,“s”);
    auth;
    //xml = new XMLHttpRequest();
    //xml.setRequestHeader(“Authorization”, auth);
    //xml.open(“GET”,url)
    //xml.responseXml;

To download the necessary files for this recipe, refer to the attached ZIP package.
Base64.zip (2.4 KB)