Showing posts with label java script. Show all posts
Showing posts with label java script. Show all posts

Javascript in OBIEE to Search a Report and Custom Data Format

How it would be if we can incorporate a Search kind of functionality so that when user put the search string in text box and press Go it will search from the list of reports from inside catalog ?
This is more or less similar kind of functionality that Catalog  Search functionality gives :
Javascript Search Catalog Report1
However there is limitation as this  Search only maps to the name of the Physical file inside the catalog directory and this name might not what end user interested for while searching . So idea is that maintain a logical catalog file name and actual physical catalog file name mapping in a backend table .Moreover end user might not have access to the answers for Searching or they might interested for this features from Dashboard page itself . Then you need to think something different to achieve your goal as one of our client demands the direct Report Search facility from Dashboard .
To achieve this I have imported the default EMP and DEPT table from Scott Schema .Create a table called “REPORT_SEARCH” and insert few rows as below .
Javascript Search Catalog Report2
Create the below simple reports .
Javascript Search Catalog Report3
And place the ‘Emp_Rep’ under ‘Emp’ Dashboard page ,’Dept_Rep’ under ‘Dept’  page , ‘Emp_Sal’ under ‘Sal’ page . And finally the Report Search template under ‘Report Search’ Page .
Javascript Search Catalog Report4
The objective is to input the report names i.e in the database in ‘Report_Name’ column and click on Find (Don’t press enter it will not work) will find the report it and you can click on it to open it .
Lets Edit the dashboard page ‘Report Search’ to see  the components .
Javascript Search Catalog Report5
So its simple text type having HTML Markup code as below .Note that I have added Javascript here to catch the user input and pass this value to URL using the Action Navigation and passing filters as parameters mechanism .(Take the reference of the detail from Bookshelf http://download.oracle.com/docs/cd/E12103_01/books/AnyWebAdm/AnyWebAdm_APIWebIntegrate6.html)
==================================
<html>
<script language=”javascript” type=”text/javascript”>
function foo(f){
var input=f.str.value;
var url=’saw.dll?Dashboard&PortalPath=/shared/Test%20Reports/Report%20Search&Page=Target&Action=Navigate&P0=1&P1=cany&P2=”REPORT_SEARCH”.”REPORT_NAME”&P3=’+input;
location.href=url;
}
</script>
<body>
<form name=’authentication’ method=’post’>
<font Color=Blue><i><b> Enter the Name of the Report to Search : </font>
<br><br>
<input type=’text’ id=’str’>
<input type=button value=’Find’ onclick=”foo(this.form);”>
</form>
</body>
</html>
===============================
Now My Javascript is ready to handle any input string .See the url portion .As per the Portal Path definition I have ‘Report Search’ report saved under “/shared/Test Reports” and the report has been placed under page called “Target” . However the Target page kept hidden .Lets see the target page then :
Javascript Search Catalog Report7
Its a combination of Tabular report and a narrative using the both option open i.e either click on “Go to Report” or Click on the Report name itself . So here is Report search Criteria .Note that the last Report Catalog column is hidden to drive the narratives using “@3″ syntax .
Javascript Search Catalog Report8
Javascript Search Catalog Report9
Now see the “Table” view “Custom Text Format ” .This will necessarily take us to the physical location of the report where it actually saved as the catalog column fetched the data from database as “Catalog_Path” and I have converted it to Custom format for ease of navigation .
Javascript Search Catalog Report10
And finally the “Narrative” as below :
Javascript Search Catalog Report11
How hide that “Target” Page and Go to Report Search Page and put the report name say “Emp” and Click on Find (Don’t press Enter ,it will not work as per Jscript code)
Javascript Search Catalog Report6 You should not see below error at the bottom left of your Browser Status bar .If this display it will indicate there must have some problem in your Java script code.
Otherwise enter ‘Emp’ as initial of “Employee” Report Name .Your report list will be filtered out and display as below . Click either on “Go to Report” or “Emp Salary” or “Employee” to redirect to the intended page .Note that since the Action Navigate use  cany as P1 parameter that means it will search for “Contains Any” word match and hence result two reports . Two return only employee reframe your search using “Employee” . Similary do the same for “Department” .
In my case I Search “Salary” and it fires the below query :
select distinct D1.c1 as c1,
D1.c2 as c2,
D1.c2 as c3
from
(select distinct T248.REPORT_NAME as c1,
T248.CATALOG_PATH as c2
from
REPORT_SEARCH T248
where ( T248.REPORT_NAME like concat(concat(‘%’, ‘Salary’), ‘%’) )
) D1
order by c1, c2
Then click on ‘Emp Salary’ or ‘Go to Report’  let me take on the  Employee Salary Page .Thus we achieve the report search functionalities across several steps .However the maintainability is the concern if the report moves from one catalog folder to other then we need to track them down and modify the backend table with the updated link otherwise the report throw error :)
Javascript Search Catalog Report13

Oracle BI EE 10.1.3.3/2 – Calling Java Scripts and Java Classes from iBots

One of the very good features of BI EE is its ability to call custom Java Scripts and Java Classes after the execution of iBots. Lets look at some examples today. In the first example we shall see how to save the reports scheduled via ibots to a local directory using a simple Java Script. It is assumed that you have your scheduler up and running. The first step in this process is to create a simple Java Script like the one below. I have taken this directly from the docs for demonstration purposes. You can customize this to your needs.
var FSO = new ActiveXObject(“Scripting.FileSystemObject”);
var fileName = “D:\\” + Parameter(1);
var fooFile = FSO.CopyFile(Parameter(0), fileName, true);
As you see above what this Java Script basically does is that it accepts one parameter (Parameter(1)) which is the file name and saves this file to a desired location that is in D drive. You need to save this file under {OracleBI}\server\Scripts\Common folder.
      
      
Once this is done, the next step is to call these scripts in your ibots. For example, lets choose a dashboard for content, PDF for attachment and schedule it to run immediately. In the Advanced of this ibot, choose the Java Script that you had created earlier. Remember you need to pass the file name (in my case it is sample.pdf) for Parameter(1) as a parameter.
      
      
      
      
      
The above was pretty straight forward. All we needed to do was to put the custom Java Script in a designated folder and call that in the Advanced tab of an ibot. Now lets look at calling a Java Class from an Ibot. There are certain things that we need to understand before we proceed further. Oracle Delivers uses the Java Host Service to make calls to a Java Procedure. So, if you go to {OracleBI}\web\javahost you would find a directory called Scheduler. Under this directory you would find a jar file called schedulerrpccalls.jar. This is the scheduler jar file that we can use to directly obtain the scheduler objects like the iBot attachments, the instance, job ids etc. So, our aim is to call a Java Program after the execution of an iBot is to write the details of the iBot schedule to a text file. In this example, i shall be using JDeveloper. Lets look at the steps one by one.
1.   Open the Config.xml file under {OracleBI}\web\javahost\config in a text editor. Search for the Scheduler tag and change it as shown below.
<Scheduler>
 <Enabled>True</Enabled> <DefaultUserJarFilePath>D:\Oracle\OracleBI\web\javahost\lib</DefaultUserJarFilePath>
</Scheduler>
The reason why we are changing the above tags is to make Java Host aware of the Java Classes that scheduler would be calling. And the DefaultUserJarFilePath tag points to the directory where we would be placing our Jar file( custom jar file using our custom Java Class). After changing this restart the Java Host Service.
2.   Open JDeveloper and create a simple Application, Project with a simple Java Class. In my case i have created a simple Application called SAWSched which in turn has an application called sawsched. The final class file that i created under this project is called as sawsched.java.
3.   In this custom java file lets include the following code. Ensure that you are including the schedulerrpccalls.jar in your Project Properties.
      
package sawsched;import java.io.*;
import java.lang.Thread;
import com.siebel.analytics.scheduler.javahostrpccalls.SchedulerJavaExtension;
import com.siebel.analytics.scheduler.javahostrpccalls.SchedulerJobException;
import com.siebel.analytics.scheduler.javahostrpccalls.SchedulerJobInfo;
public class sawsched implements SchedulerJavaExtension{
public void run(SchedulerJobInfo jobInfo) throws SchedulerJobException
{
System.out.println(“JobID is:” + jobInfo.jobID());
System.out.println(“Instance ID is:” + jobInfo.instanceID());
System.out.println(“JobInfo to string is:” + jobInfo.toString());
try
{
File outputFile = new File(“D:\\JavaJob.txt”);
File attachFile = jobInfo.getResultSetFile();
attachFile.createNewFile();
FileWriter out = new FileWriter(outputFile);
out.write(“User ID:\t\t” + jobInfo.userID() + “\r\n”);
out.write(“Job ID:\t\t” + jobInfo.jobID() + “\r\n”);
out.write(“Instance ID:\t\t” + jobInfo.instanceID() + “\r\n”);
out.write(“Parameter Count:\t\t” + jobInfo.parameterCount() + “\r\n”);
out.write(“File Path: ” + attachFile.getAbsolutePath());
for(int i = 0; i < jobInfo.parameterCount(); ++i)
{
out.write(“\tParameter “);
out.write(new Integer(i).toString());
out.write(“:\t” + jobInfo.parameter(i) + “\r\n”);
}
out.close();
}
catch(Exception ex)
{
throw new SchedulerJobException(1, 1, ex.getMessage());
}
}
public void cancel()
{
}
}
      
What this class basically does is it creates a text file which would have details about the iBot job. The above example is available in the bookshelf.
4.   Once this is done compile this code to ensure that you have no errors. The next step is to create a JAR file out of this class. So, right click on your Project and create a Jar File. In your JAR ensure that you are also including your schedulerrpccalls.jar and the above compiled class.
      
      
      
I have named my Jar file as BISched.
      
      
Once this is done right click on your resources ( you would find your Jar there) and then click on Deploy.
      
Copy your Deployed Jar file to {OracleBI}\web\javahost\lib (The one that we included in the DefaultUserJarFilePath tag).
      
5.   Now lets go back to delivers and create a simple iBot and choose Java Program in the Advanced Options.
      
In the Java Properties enter the class name, in our case it is sawsched.sawsched and then in the CLASSPATH enter the jar file that we had bundled. Save the ibot and you would notice that a text would have been created under D drive.