Skip to Content

UPDATE : For those who just need a way to copy variables from one document to another, take a look at the update at the end of this document.

Hi,

I would like to share a small script to include variables from one WEBI document to another. I´m using Javascript and the code is a HTML document.

I think it will be usefull because you can build a document with some variables and then reuse it , with minimum effort, in another document.

It works on SAP BO BO 4.1 SP3 on

PREMISES

1 – There is a WEBI doc that holds the definition of the variables which ID is  DocIdFrom;

2 – You want to include the variables to a WEBI doc which ID is DocIdTo

3 – You have just one query in DocIdTo  (Query 1)

4 – The variables to be inserted are only those which has objects that has corresponding objects in Query 1

5 – Variables that depends on another variable will not be inserted at first, run the script again to insert them

WORKFLOW

1 – Logs into the platform

2 – Gets the list of variables from DocIdFrom

3 – Loops through the list to get its definition

4 – insert the variables into DocIdTo

5 – Logs off the platform

There goes the script :

<html>

<head>

</head>

<body>

<script>

debugger;

// Logs into the platform

var logon = new XMLHttpRequest();

    var url = ‘http://<server>:6405/biprws/logon/long’;

    var action = ‘logon/long’;

    var body = ‘<?xml version=”1.0″?><attrs xmlns=”http://www.sap.com/rws/bip“><attr name=”userName” type=”string”>USERID</attr><attr name=”password” type=”string”>PASSWORD</attr><attr name=”auth” type=”string” possibilities=”secEnterprise,secLDAP,secWinAD”>secEnterprise</attr></attrs>’;

    var response;

    var logonToken;

    logon.open(‘POST’, url, false);

    logon.setRequestHeader(‘X-PINGARUNER’, ‘pingpong’);

    logon.setRequestHeader(‘Content-Type’, ‘application/xml’);

    logon.setRequestHeader(‘Accept’, ‘application/xml’);

    logon.send(body);

   logonToken = logon.getResponseHeader(‘X-SAP-LogonToken’);

   token=logonToken;

   logonToken= logonToken.substring(1,logonToken.length-1);

   logonToken=encodeURIComponent(logonToken).trim();

// gets the list of variables

    var getListVar = new XMLHttpRequest();

    var url = ‘http://<server>:6405/biprws/raylight/v1/documents/’+DocIdFrom+’/variables’;

    getListVar.open(‘GET’, url, false);

    getListVar.setRequestHeader(‘X-PINGARUNER’, ‘pingpong’);

    getListVar.setRequestHeader(‘Content-Type’, ‘application/xml’);

    getListVar.setRequestHeader(‘Accept’, ‘application/xml’);

    getListVar.setRequestHeader(‘X-SAP-LogonToken’, token);

    getListVar.send();

    var def=getListVar.responseText;

    var nodesVar = getListVar.responseXML.getElementsByTagName(“id”);

 

    // loops through the variable list

    for (i=0;i<nodesVar.length;++i)

    {

 

    // gets the variable original definition

        idVar = nodesVar[i].innerHTML;

        var getSpecVar = new XMLHttpRequest();

        var url = ‘http://<server>:6405/biprws/raylight/v1/documents/’+DocIdFrom+’/variables/’+idVar;

        getSpecVar.open(‘GET’, url, false);

        getSpecVar.setRequestHeader(‘X-PINGARUNER’, ‘pingpong’);

        getSpecVar.setRequestHeader(‘Content-Type’, ‘application/xml’);

        getSpecVar.setRequestHeader(‘Accept’, ‘application/xml’);

        getSpecVar.setRequestHeader(‘X-SAP-LogonToken’, token);

        getSpecVar.send();

    

// inserts the variable

        var setSpecVar = new XMLHttpRequest();

        var url = ‘http://<server>:6405/biprws/raylight/v1/documents/’+DocIdTo+’/variables’;

        setSpecVar.open(‘POST’, url, false);

        setSpecVar.setRequestHeader(‘X-PINGARUNER’, ‘pingpong’);

        setSpecVar.setRequestHeader(‘Content-Type’, ‘application/xml’);

        setSpecVar.setRequestHeader(‘Accept’, ‘application/xml’);

        setSpecVar.setRequestHeader(‘X-SAP-LogonToken’, token);

        setSpecVar.send(def);

    }

// saves the document

var saveDoc = new XMLHttpRequest();

    var url = ‘http://<server>:6405/biprws/raylight/v1/documents/’+DocIdTo;

    saveDoc.open(‘PUT’, url, false);

    saveDoc.setRequestHeader(‘X-PINGARUNER’, ‘pingpong’);

    saveDoc.setRequestHeader(‘Content-Type’, ‘application/xml’);

    saveDoc.setRequestHeader(‘Accept’, ‘application/xml’);

    saveDoc.setRequestHeader(‘X-SAP-LogonToken’, token);

    saveDoc.send();

   // logs off

var logoff = new XMLHttpRequest();

    var url = ‘http://<server>:6405/biprws/logoff’;

    logoff.open(‘POST’, url, false);

    logoff.setRequestHeader(‘X-PINGARUNER’, ‘pingpong’);

    logoff.setRequestHeader(‘Content-Type’, ‘application/xml’);

    logoff.setRequestHeader(‘Accept’, ‘application/xml’);

    logoff.setRequestHeader(‘X-SAP-LogonToken’, token);

    logoff.send();

    console.log(logoff.responseText)

 

</script>

</body>

</html>

Cheers,

Rogerio

UPDATE 05/26/2015

There´s a much easier way of copying variables from one document to another.

Since BO 4.1 SP3, you can copy blocks from one (DOC A)  document to another (DOC B) in WEBI Rich Client. In order to do so, right click the block you want to and choose copy, go to the other document right click and Paste. (it will take a while to the process to end (sometimes it can take some minutes).

When you copy the block, the associated quey(ies)  (the one(s) that brings the respective data from the block will be copied as well.

If you need to copy some variables from DOC A to DOC B, just create a dummy block with these variables in DOC A and then Copy and Paste the block into DOC B

To report this post you need to login first.

5 Comments

You must be Logged on to comment or reply to a post.

  1. Agata Kubera

    Hello Rogerio,

    Today I tried to run the above script, but I didn’t get far 🙁

    I exchanged the <server>, USERID, PASSWORD; DocIdFrom; DocIdTo in the script with my own credentials, saved the file as “WEBI-REST-Script.html” on the desktop but nothing happens when I run it.

        

    Could you please advise me how to get it work?

        

    (I was able to obtain the Token via the RESTful Chrom-Client “Postman”, so in general the service on the BO-Server seems to work)

    Kind regards

    Agata

    (0) 
    1. Rogerio Plank Post author

      Hello Agata,

      So sorry about my very late reply.

      Can you do me a favor ? On google chrome, press F12 (this will open the debugger) on the top of the window, click at Console. Press CTRL+PrintScreen and paste it on word.

      Can you send me the file ?

      Cheers,

      Rogerio

      (0) 
      1. Agata Kubera

        Hello Rogerio,

        never mind, happy to hear from you 🙂

        Here ist the screen you requested, and thank you for your help.

        Chrom_Debugger.jpg

        Regards

        Agata

        (0) 
  2. Bulent Ozgul

    Hi Rogerio,

    Another newbie 🙂

    I’ve just started yesterday for my first restful sdk and faced with my first error 🙂

    if i debug the code i get an error on the

    // gets the variable original definition

            idVar = nodesVar[i].innerHTML;

    line. if i checked the value for idvar it shows “undefined”. i add a watch for “nodesvar” and i see the values for the i=0 node. but couldn’t see a “innerhtml” method/object value.

    the code runs fine until this line. logon is successful, the “def” variable shows the variable of my “from” document.

    do you have any idea?

    By the way thanks a lot for your post. At least i can log on to my BI system via restful SDK and can do something. Your code was very helpful for me.

    (0) 
    1. Bulent Ozgul

      I change the code like this and now it’s working:

      delete the line

      var def=getListVar.responseText;


      put these line

      var def=getSpecVar.responseText;

      after the line

      getSpecVar.send();

      (0) 

Leave a Reply