2 Replies Latest reply on Dec 22, 2014 7:43 AM by Spencer Swartz

    call getAllowableValues() from the Java script api

    Spencer Swartz

      I am having trouble calling the getAllowableValues() function in this java script... Im sure it is because I am not calling the Parameter class but in the API documents it does not seem there is an obvious way to do this. here is my code so far.

       

      Thanks for the help in advance....

       

      Spencer

       

       

      window.onload=function() {

        var vizDiv = document.getElementById('viz');

        var vizURL = 'http://tableau.corporate.---------------------------------';

        var options = {

        width: '764px',

        height: '855px',

        hideToolbar: true,

        hideTabs: true

        };

        viz = new tableauSoftware.Viz(vizDiv, vizURL, options);

       

       

      };

      function getParams(sheetParam) {

        parameter = viz.getParameter();                                <------------------------ This is not correct... I'm just not sure what needs to go here.

        paramVals = parameter.getAllowableValues();

        text= "hello world" + paramVals;

        alert(text);

      };

        • 1. Re: call getAllowableValues() from the Java script api
          Russell Christopher

          Do this:

           

          function renderViz() {
          
          
              // Define variables for viz
              var mainVizDiv = $("#mainViz");
              var mainWorkbookUrl = "https://" + serverName + "/t/SkunkWorks/views/JavaScriptTarget/Dashboard";
              var mainVizOptions = {
                  hideTabs: false,
                  hideToolbar: false,
                  //toolbarPositon: top  (or "bottom")
                  width: mainVizDiv.parent().innerWidth() + "px",
                  height: mainVizDiv.parent().innerHeight() + "px",
                  onFirstInteractive: function () {
                      mainWorkbook = mainViz.getWorkbook();
                  }
              };
              //  Create viz
              mainViz = new tableauSoftware.Viz(mainVizDiv[0], mainWorkbookUrl, mainVizOptions);
          }
          

           

           

          ....Then you could call something like this:

           

          function parameters_getAllowableValues() {
          
              //String Parameter
          
              mainWorkbook = mainViz.getWorkbook();
              var onSuccess = function (params) {
                  var outputText = "Name: ";
                  // Param Name
                  outputText = outputText + params.get("Cute Animals").getName() + "\n\n";
          
          
                  var foo = params.get("Top Customers");
                  // Allowable Values
                  var allValues = [];
                  $.each(params.get("Cute Animals").getAllowableValues(), function (Value, i) {
                      //use .value or .formattedValue of the DataValue object represented by variable i
                      var str = i.value;
                      allValues.push(str);
                  });
                  outputText = outputText + "Allowable Values: " + allValues.join(", ");
          
                  alertOrConsole(outputText);
             };
             
          
               var onError = function (err) {
                  alertOrConsole("Whoops");
              };
          
              mainWorkbook.getParametersAsync().then(onSuccess, onError);
          
          }
          
          • 2. Re: call getAllowableValues() from the Java script api
            Spencer Swartz

            Thank you Russell, This seems to have worked... my plan is to use the values in a dropdown menu (that is self populated) to select from. I looks like it actual grabs the value of the parameter compaird to the displayed as, I assume that I need to change something within this part of the code

             

                    $.each(params.get("Cute Animals").getAllowableValues(), function (Value, i) {  

                        //use .value or .formattedValue of the DataValue object represented by variable i  

                        var str = i.value;

             

            Thanks for all of your help!