Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member

   Hi Everyone,

I would like o share two extra approaches to make use of persistent comments into a WEBI doc. I´m saying two extra ways because this subject has already been  discussed by william.marcyinEnabling Comments in Web Intelligence Reports using Input Controls

The first approach works only in design mode, the second ,albeit working on reading mode, can be better explored in design mode.

1) First approach - Use of blank cells.

    This approach is based in the use of blank cells and consists , simply in dropping blank cells at the places where you want the comments to be in the report. One can simply double click on the cell to edit its content. And, if the person wants the comment to have multilines, just edit the content using the formula editor.

2) The second approach makes use of HTML5 and Javascript, and saves the comments to a Database to further access. In this particular example, I´m using MongoDB (www.mongodb.com) as a dataprovider and Mongolab (www.mongolab.com) as a DaaS provider. I´m not sure about it, but I think that you can use SAP Hana as the dataprovider (to be confirmed), anyway, any Database that has a Javascript driver will do.

The reason why I choose MongoDB are two folded :

a- Flexibility - As a key-value NoSQL database, MongoDB can hold any kind of data in a very interesting way. You can literaly save a variable to Mongo without any e3ffort

b - Ease of use - Mongolab has a Rest API to perform Database operations, in this sample I´m using a Rest call to write to Mongo and a second one to write. Besides, mongolabs provids a free plan (the one used).

I used a query over e-fashion that returns [Lines]. My report consists on a vertical table with two columns :

- [Lines] and

- [comments] , a measure variable with the following formula :

        ="<div><textarea id='"+[Lines]+"'></textarea></div>" and its "Read as" property to HTML.

For those unfamiliar with HTML, variable will generate, for each [Lines], a small textbox, where the user will enter its comments.

There are three blank cells that holds the HTML for the click buttons and some Javascript code to read and write from Mongolabs.

The script are :

1 - Save button  - <input type = "button" value="Save Comments" onclick="saveComments()"

2 - read button - <input type = "button" value="Read Comments" onclick="readComments()"

3 - Script to read and write from the database

<script>

// array to hold the documments retrieved from the Database

var arrCom =[];

// the structure of the documment to be saved

function Comment ()

{

  this.line="";

  this.text="";

}

// function to save the comments to Mongo

function saveComments() {

var txt=""


// comments will be an array with the textarea elements

var comments=document.getElementsByTagName("textarea");

// loops through the array , creating a new document, and adding it to the array filling its values, and pushing it to the array

for (i=0;i<comments.length;++i) {

   var   com = new Comment();

   com.line=comments[i].id;

   com.text=comments[i].value;

   arrCom[arrCom.length]=com

  }

var enq="";

enq=JSON.stringify(arrCom);

//Rest call to save the comments to the Database

     var invocation = new XMLHttpRequest();

     var url = 'https://api.mongolab.com/api/1/databases/bobj/collections/bobj?m=true&apiKey=IZzAl7-Sd8i9SZMJ25lpSSs...'

     invocation.open('PUT', url, false);

   invocation.setRequestHeader('X-PINGARUNER', 'pingpong');

   invocation.setRequestHeader('Content-Type','application/json');

   invocation.setRequestHeader('Accept','application/JSON');

   invocation.send(enq);

}

// function to read the comments from the database

function readComments() {

var arrComments= [];

var invocation = new XMLHttpRequest();


// Rest call to read the comments into arrComments, an array

var url = 'https://api.mongolab.com/api/1/databases/bobj/collections/bobj?apiKey=IZzAl7-Sd8i9SZMJ25lpSSsT_45xNN...'

     invocation.open('GET', url, false);

   invocation.setRequestHeader('X-PINGARUNER', 'pingpong');

   invocation.setRequestHeader('Content-Type','application/json');

   invocation.setRequestHeader('Accept','application/JSON');

   invocation.send();

   arrComments= JSON.parse(invocation.responseText)


  // loops through the array and, for each element, finds its correpondent textarea assigning its value

   for (i=0;i<arrComments.length;++i) {

       document.getElementById(arrComments[i].line).value=arrComments[i].text;

  }

}

</script>

Notice that :

1 - This sample was elaborated as a proof of concept, swo is lacking a lot of funcionality;

2 - The Rest API, in the way is used in this sample, isn´t a good implementation

I´m attaching a wid file to the post with this example. It has a txt extension so it can be uploade. It´s on 4.1 SP6, To use it, first change its extension from txt to wid, open it with WEBI Rich Client and exports it to BI Launch PAD,

cokments will be highly appreciated

Regards,

Rogerio

8 Comments
Labels in this area