Hitachi Vantara Pentaho Community Forums
Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Using listeners and running xaction

  1. #1

    Default Using listeners and running xaction

    I've got a pie chart component setup to run when the date value changes in my date drop down box. What seems to be happening though is that the xaction for the chart is always one step behind. Say I choose to run the chart with Prior YTD (which is different than what is originally set as the chosen value), the xaction doesn't run, but then I choose a new value from the dropdown and the xaction kicks off and runs but it is running the query for Prior YTD.

    Any ideas on this?

    I've attached the xaction and here is the template.html code
    Code:
    <form name="myForm">
    <!-- The dashboard layout table -->
    <table align="center" style="border: 0px solid #000;">
     <tr>
      <td align="center" colspan="2">
       <!-- The page_title_object -->
       <p><h3><span align="center" id=text_object></span></h3></p>
      </td>
     </tr>
     <tr>
      <td>
      <table style="width: 100%; text-align: left; margin-left: auto; margin-right: auto;"
       border="0" cellpadding="2" cellspacing="2">
       <tbody>
        <tr>
         <td  style="width: 50%; text-align: center; vertical-align: middle;">
          Select Company(s): <div id="comp_selectMulti"></div>
         </td>
         <td  style="width: 50%; text-align: center; vertical-align: middle;">
          Select Date: <div id="date_select"></div>
         </td>
        </tr>
        <tr>
         <td>
          <div id="prodClassSales_PieChart"></div>
         </td>
         </tr>
       </tbody>
      </table>
      </td>
     </tr>
    </table>
    </form>
    </script>
    <script language="javascript" type="text/javascript">
    var stringDate=null;
    var region="test";
    var dateStart="2007-01-01";
    var comp="0000";
    var start_date=null;
    var end_date=null;
    var stryear = null;
    var strmonth = null;
    var strday = null;
    var intmonth;
    var intday;
    var intyear;
    var strDesc;
    var date = null;
    function setDates()
    {
     start_date = new Date();
     end_date = new Date();
     now = new Date();
     DateDayNm = "";
     var weekday=new Array(7);
     weekday[0]="Sunday";
     weekday[1]="Monday";
     weekday[2]="Tuesday";
     weekday[3]="Wednesday";
     weekday[4]="Thursday";
     weekday[5]="Friday";
     weekday[6]="Saturday";
     DateMonth = now.getMonth();
     DateDay = now.getDay();
     DateYear = now.getFullYear();
     switch (date)
     {
     case "Current YTD":
      strDesc = "Current YTD: ";
      break;
     case "Prior YTD":
      start_date.setDate(start_date.getDate()-365);
      strDesc = "Prior YTD: ";
      break;
     }
     intyear = start_date.getYear();
     stryear = intyear.toString();
     intmonth = start_date.getMonth();
     intmonth = intmonth + 1
     strmonth = intmonth.toString();
     if (strmonth.length == 1)
     {
      strmonth = "0"+strmonth;
     }
     intday = start_date.getDate();
     strday = intday.toString();
     if (strday.length == 1)
     {
      strday = "0"+strday;
     }
     stringDate = stryear + strmonth + strday;
     alert(strDesc + " " + stringDate);
    }
    
    dateSelector =
    {
      name: "dateSelector",
      type: "select",
      solution: "dashboards",
      path: "sales_dashboard",
      action: "dates.xaction",
      parameters:[],
      parameter:"date",
      htmlObject: "date_select",
      executeAtStart: true,
      preExecution:function(){},
      postExecution:function(){setDates();Dashboards.processChange(this.name);},
      postChange:function(){setDates();}
    }
    companySelectorMulti =
    {
      name: "companySelectorMulti",
      type: "selectMulti",
      solution: "dashboards",
      path: "sales_dashboard",
      action: "company.xaction",
      parameters:[],
      parameter:"comp",
      size: "4",
      htmlObject: "comp_selectMulti",
      executeAtStart: true,
      preExecution:function(){},
      postExecution:function(){Dashboards.processChange(this.name);}
    }
    prodClassSalesPieChart =
    {
      name: "prodClassSalesPieChart",
      type: "xaction",
      solution: "dashboards",
      path: "sales_dashboard",
      action: "prodClassSalesPieChart.xaction",
      listeners:["date"],
      parameters: [["DATEVAL","stringDate"]],
      htmlObject: "prodClassSales_PieChart",
      executeAtStart: false,
      preExecution:function(){},
      postExecution:function(){}
    }
    var components = [dateSelector,companySelectorMulti,prodClassSalesPieChart];
     
    </script>
    <script language="javascript" type="text/javascript">
    
    function load(){
     Dashboards.init(components);
    }
    load();
    </script>
    Attached Files Attached Files

  2. #2
    Join Date
    Jul 2007
    Posts
    2,497

    Default

    Shouldn't your Dashboards.processChange be on the postChange? postExecution is fired only once - when the component is rendered
    Pedro Alves
    Meet us on ##pentaho, a FreeNode irc channel

  3. #3

    Default

    That's what I thought too. But when I put it there along with the setDates function call, I just get an infinite loop. In the example for sample_dashboard_broadcast, the ProcessChange is located in the POST_EXECUTION function which is why I placed mine there as well. Again though, if I click on the dropdown 3 times it will finally execute the xaction based on the criteria from my 2nd click on the dropdown box which means, to me, that the POST_EXECUTION function is getting kicked off more than once, or am I not understanding how something works.

  4. #4
    Join Date
    Jul 2007
    Posts
    2,497

    Default

    I didn't pay much attention to your template, but basically this is what happens:

    postExecution is executed after the selector is rendered. If that selector doesn't have any listeners, it's executed only once on it's lifetime.

    postChange is executed after you select something. (same line of thought for "pre")
    Pedro Alves
    Meet us on ##pentaho, a FreeNode irc channel

  5. #5

    Default

    OK, that makes sense, thanks.

    But I guess I still don't know why my pie chart is not executing each time the selector changes? Which you said I should put my ProcessChange in the PostChange to get that to happen but then it goes off into an infinite loop.

  6. #6

    Default

    After more research I see what's happening but why it doesn't work I'm not sure. Maybe someone can help me on this.

    I have a drop down set up for choosing the type of date (Current Year to Date, Today, Prior Year to Date, etc.) this value is associated with the parameter date. When this value changes I call the function setDates which then translates the value chosen from the drop down to an actual date value to be used in the query that is in my xaction. What seems to happen though is that I can't call a function and still have the listener work correctly. I don't want to have to put the code to translate the type of date to a real date in each of my xaction files because that is redundant and a coding nightmare.

    So I have 2 questions, can I put the code that does the translation into a .js file and include the .js file in the xaction's JavaScript Process Action? If so, is it as simple as including a regular javascript file in .html? If not, can someone explain. Or is there a way to get the translation code to remain where I have it but get the listeners and the xactions to work properly.

    Thanks
    Bob

  7. #7
    Join Date
    Jul 2007
    Posts
    2,497

    Default

    Quote Originally Posted by BobN View Post

    What seems to happen though is that I can't call a function and still have the listener work correctly.
    As far as I know this is absolutely not true.

    I think you're going through the most difficult way here. Do this:

    1. Adapt that function so that it accepts an argument and returns what you want, something like getDateFromValue(date).

    2. Remove all post/pre functions. You don't need them

    3. Instead of parameters: [["DATEVAL","stringDate"]], use parameters: [["DATEVAL","getDateFromValue(date)"]], keeping "date" as the listener
    Pedro Alves
    Meet us on ##pentaho, a FreeNode irc channel

  8. #8

    Default

    Thanks! That worked perfect. I do have another question/issue though. So I've had to change my setDates function a bit to return a starting and ending date, which I'm trying to pass to the XACTION to be used as part of query. My question is two fold. First, how should I return the values from the setDates function? I figured I'd pass then back as an array. Second, what is my input type then on the XACTION and how do I use those values in the query?

    I did return the values as an array and I set up the input value on the XACTION to be a result-set type and then tried to use {PREPAREATEVAL[0]} in my query but it didn't work so I'm just wondering how to accomplish what I want.

    Thanks
    Bob

  9. #9
    Join Date
    Jul 2007
    Posts
    2,497

    Default

    Quote Originally Posted by BobN View Post
    So I've had to change my setDates function a bit to return a starting and ending date, which I'm trying to pass to the XACTION to be used as part of query. My question is two fold. First, how should I return the values from the setDates function?

    Well, my suggestion was to use a function to return one date only, mainly to avoid those questions
    Pedro Alves
    Meet us on ##pentaho, a FreeNode irc channel

  10. #10

    Default

    Quote Originally Posted by pmalves View Post
    Well, my suggestion was to use a function to return one date only, mainly to avoid those questions
    Sorry, maybe I'm misunderstanding your explanation. I'm not asking how I would return an array via a Javascript function, I know how to do that, I'm asking if this is what I would do and number 2 what is the type I should set for my input variable on the XACTION.

    If your response was meant to be there isn't an explanation or answer, then OK, thanks for the help on the other stuff.

    As a side note, I did find a work around but not one that I think is highly efficient. I take the 2 dates and concatenate them into a string, return the string to the dashboard object to be passed to the xaction and within the xaction the input is a type string and then in the query I SUBSTRING the input value.

    Thanks
    Bob

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Privacy Policy | Legal Notices | Safe Harbor Privacy Policy

Copyright © 2005 - 2019 Hitachi Vantara Corporation. All Rights Reserved.