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

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

5 Comments
Labels in this area