title: Scripted Data Source using JSON not working with BIRT while working in Java Class
body: <p>I will talking throw codes line with a few words, In alfresco I need to create a reports using its Workflows APIs that response as JSON, I found the solution for using JSON as a Data Source in this link (this will be good reference to full understand my issue) :</p>
  
  <p><a href="http://www.birt-exchange.org/org/devshare/designing-birt-reports/1053-scripted-data-source-using-json/" rel="nofollow">http://www.birt-exchange.org/org/devshare/designing-birt-reports/1053-scripted-data-source-using-json/</a></p>
  
  <p>I downloaded the source and I understand how its works, and finally I was having a problem "authentication issue" and solved it by editing source file 'JSONParser.java', anyway I have another problem now, I have the following code in Java thats working:</p>
  
  <pre><code>package com.actuate.json.test;
  import java.io.IOException;
  import com.actuate.json.JSONParser;
  public class TestJSONParse_OutBound {
      public static void main(String[] args) {
          try{
              JSONParser theParser = new JSONParser();
              theParser.loadData("http://localhost:8080/alfresco/service/api/workflow-definitions/activiti$CS-Outbound-WFPD:5:403/workflow-instances?state=active&amp;amp;format=json","admin","admin");
              System.out.println("Number of jobs found: " + theParser.getChildCount("data") + "\n");
              for(int i = 0; i &lt; theParser.getChildCount("data"); i++){
                  System.out.println(String.valueOf(i + 1) + ")  " + theParser.getValue("data", "description", i));
                  System.out.println("\tID: " + theParser.getValue("data", "id", i));
                  System.out.println("\tURL: " + theParser.getValue("data", "url", i));
                  System.out.println("\tUsername: " + theParser.getValue("data", "initiator/firstName", i));
              }
          }catch (IOException ioe) {
              // TODO: handle exception
          }catch(Exception ex){
  
          }
      }
  }
  </code></pre>
  
  <p>Result :</p>
  
  <pre><code>Number of jobs found: 2
  
  1)  CS-Outbound-WFPD
      ID: activiti$499
      URL: api/workflow-instances/activiti$499
      Username: Administrator
  2)  CS-Outbound-WFPD
      ID: activiti$404
      URL: api/workflow-instances/activiti$404
      Username: Administrator
  </code></pre>
  
  <hr>
  
  <p>BUT In BIRT Report in eclipse IDE no luck 1, in Scripted Data Source I put:</p>
  
  <pre><code>count = 0;
  controller = new Packages.com.actuate.json.JSONParser();
  controller.loadData(params["JSONURL"],params["USERNAME"],params["PASSWORD"]);
  totalCount = controller.getChildCount("data");
  </code></pre>
  
  <p>and fetch rows in data set table like : </p>
  
  <pre><code>if(count &lt; totalCount){
      row["id"] = controller.getValue("data", "id", count);
      row["url"] = controller.getValue("data", "url", count);
  
      count++;
      return true;
  }
  return false
  </code></pre>
  
  <p>But still giving me white page with head titles only, empty cells !!.</p>
  
  <p>To get exception I uploaded it to Alfresco integrated with BIRT, and I got :</p>
  
  <pre><code>WARNING: Fail to execute script in function __bm_OPEN(). Source:
  ------
  " + count = 0;
  controller = new Packages.com.actuate.json.JSONParser();
  controller.loadData(params["JSONURL"],params["USERNAME"],params["PASSWORD"]);
  totalCount = controller.getChildCount("data"); + "
  -----
  A BIRT exception occurred. See next exception for more information.
  Error evaluating Javascript expression. Script engine error: TypeError: [JavaPackage com.actuate.json.JSONParser] is not a function, it is object. (/report/data-sources/script-data-source[@id="8"]/method[@name="open"]#2)
   Script source: /report/data-sources/script-data-source[@id="8"]/method[@name="open"], line: 0, text:
  __bm_OPEN()
  org.eclipse.birt.data.engine.core.DataException: Fail to execute script in function __bm_OPEN(). Source:
  ------
  " + count = 0;
  controller = new Packages.com.actuate.json.JSONParser();
  controller.loadData(params["JSONURL"],params["USERNAME"],params["PASSWORD"]);
  totalCount = controller.getChildCount("data"); + "
  -----
  A BIRT exception occurred. See next exception for more information.
  Error evaluating Javascript expression. Script engine error: TypeError: [JavaPackage com.actuate.json.JSONParser] is not a function, it is object. (/report/data-sources/script-data-source[@id="8"]/method[@name="open"]#2)
   Script source: /report/data-sources/script-data-source[@id="8"]/method[@name="open"], line: 0, text:
  __bm_OPEN()
      at org.eclipse.birt.data.engine.script.JSMethodRunner.runScript(JSMethodRunner.java:147)
  .
  .
  .
  Caused by: org.mozilla.javascript.EcmaError: TypeError: [JavaPackage com.actuate.json.JSONParser] is not a function, it is object. (/report/data-sources/script-data-source[@id="8"]/method[@name="open"]#2)
  .
  .
  .
  </code></pre>
  
  <p>Really I don't know what the problem is, and how to solve, if anybody have any idea for It, I spent about 1 week on it with no solution ...</p>