4 Replies Latest reply on Apr 15, 2017 8:37 AM by Rahul Tokase

    [Javascript API] Remove Custom views

    hk lee

      Hi.

      I have trouble using Javascript API method for controlling custom view.

       

      removeCustomViewAsync(String) doesn't work but, changeParameterValueAsync(String, Object), revertAllAsync() and rememberCustomViewAsync(String).

      And It just generated 500 Internal Server Error.

      A custom view called 'test' already exists.

       

      I don`t know why only this method doesn't work. Please advise me.

       

      var customViewName = 'test';

      workbook.removeCustomViewAsync(customViewName);

              

                //var url = rurl.match(/http:\/\/[a-zA-Z./]+views\//g)+targetUrl;

                <%

                    var strViewParam = JSON.stringify(viewParams);

                        strViewParam = "{"+strViewParam.substring(1, strViewParam.length-1)+"}";

                %>

                 var changedParams = <%-strViewParam%>;

                 var i= 0;

                 //console.log(workbook); 

       

       

                 for(var key in changedParams){

                     console.log(key+" = "+changedParams[key]);

                    workbook.changeParameterValueAsync(key,changedParams[key]).then

                    (

                      function() { console.log('Saved custom view ' + customViewName); },

                      function() { console.warn('Failed to save custom view ' + customViewName); }

                    );

                  

                     workbook.rememberCustomViewAsync(customViewName).then

                    (

                      function() { console.log('Remembered custom view ' + customViewName);  excel_download(); },

                      function() { console.warn('Failed to remember custom view ' + customViewName); }

                    );

                 

                   i++;

                 }

       

      Reference Link : API Reference

      스크린샷 2016-08-26 오전 11.16.10.png

        • 1. Re: [Javascript API] Remove Custom views
          Jeff D

          It looks like you're not waiting for the async call (removeCustomViewAsync) to complete.

          • 2. Re: [Javascript API] Remove Custom views
            hk lee

            As soon as removeCustomViewAsync start, 500 Internal Server Error is generated.

            Also When I called only it, 500 Error was generated.

            • 3. Re: [Javascript API] Remove Custom views
              Rahul Tokase

              Hi

              Even for me RemoveCustomView is not working. what i observed is tableau javascript api is immediately calling the otherwise block with an error view does not exist. In the other wise block only i m calling the rememberCustomView with the same name and this time it throws view already exist.

               

              Any help on this appreciated.

              • 4. Re: [Javascript API] Remove Custom views
                Rahul Tokase

                Hi

                 

                Finally i got the solution. I have debug the javascript call and this is what i found in the call.

                 

                Javascript API before removing the custom view from the server checks into internal custom view map in javascript whether view is present or not. If view is not present in the javascript api map then removeCustomViewAsync method will throw the invalidCustomViewName error.

                 

                If you have embedded the view using javascrip api and with customView=no then you wont be having customview option in the embedded view as you do not have the custom view tableau javascript api will not have the map of all the custom views.

                 

                In above case if you try to delete the already existing custom view even though it is present on the server tableau javscript api first checkes the local custom view cache first. As view is not present in the local cache map tableau javascript api will throw the invalidCustomViewName error.

                 

                So to avoid the above error I have explicitly given a call to the getCustomViewAsync method first then give a call to removeCustomViewAsync method. With this you will not get the error.

                1 of 1 people found this helpful