2 Replies Latest reply on Mar 19, 2018 3:39 PM by Michael Kovner

    Trouble with Arrays

    Michael Summons

      Hello All,

      I've been trying my best to work with the JavaScript API even though the reference materials out there are extremely basic. I am having trouble with trying to return an array of values from a filter when the filter has changed. The current function i'm working with Is below:

       

      var displayFilters = function (filters) {
        for (var i = 0; i< filters.length; i++) {  
        filterName = filters[i].getFieldName();

         if (filterName == 'PRJTASK') {
         for (var z = 0; z< filters[i].getAppliedValues().length; z++){
         filterList = [filters[i].getAppliedValues()[z].value];
           viz2.getWorkbook().changeParameterValueAsync("PRJTASKParam", filterList);
           viz3.getWorkbook().changeParameterValueAsync("PRJTASKParam", filterList); 
          console.log(filterList);
          }
         }
        }
      }

       

      The intent is to collect all of the currently selected values of a filter named "PRJTASK" (embedded in a worksheet) in an array named "filterList". The array values are then to be used to filter two other workbooks that I have on a webpage. Currently the array is only returning one value as it is generating a separate array for each value rather than including each value in a single array. It may be something simple, but can not figure it out at this point. Any help/advice would be greatly appreciated!!

        • 1. Re: Trouble with Arrays
          patrick.byrne.0

          Hello Michael,

           

          I am definitely not a developer or JavaScript expert, but I believe that the call needed to return the values from a parameter is getCurrentValue()

           

          I believe this should return all the values that are selected in the parameter currently.

           

          Cheers,

          Byrne, Patrick

           

           

          • 2. Re: Trouble with Arrays
            Michael Kovner

            It looks like you're replacing the array on each iteration of the loop instead of appending it. Try something like this...

             

            var displayFilters = function (filters) {

              var filterList = [];
              for (var i = 0; i< filters.length; i++) {  
              filterName = filters[i].getFieldName();

               if (filterName == 'PRJTASK') {
               for (var z = 0; z< filters[i].getAppliedValues().length; z++){
                 filterList.push(filters[i].getAppliedValues()[z].value);
                 console.log(filterList);
                }
               }
              }

              viz2.getWorkbook().changeParameterValueAsync("PRJTASKParam", filterList);

              viz3.getWorkbook().changeParameterValueAsync("PRJTASKParam", filterList); 

            }