4 Replies Latest reply on Apr 21, 2016 3:50 AM by Rishabh Dhingra

    Refresh Datasource from tabcmd if a condition is met using batch

    Ashish Singh

      What

      Refresh a datasource named ds_01

      How

      Write a batch file to do this. Let's call this batch my_bat.bat

      When

      I have a .csv file named flag.csv (attached)

      Either flag.csv will have this content

           flag

           1

       

      Or flag.csv will have this content

           flag

           0

       

      Batch should check the flag in CSV and if flag is 0 then datasource should not refresh, if flag is 1 then datasource should refresh.

       

      How You Can Help

      I am unable to read the CSV and check if there is 0 or 1 in the row of the CSV. If will be great if you write an IF THEN ELSE END for me in batch my_bat.bat which checks flag.csv and refreshes ds_01 conditionally.

       

       

       

      Thanks a lot,

      Ashish

        • 1. Re: Refresh Datasource from tabcmd if a condition is met using batch
          Rishabh Dhingra

          Hi Ashish,

           

          You could also use a Powershell script in order to do so. Create a configuration xml file like this to store the location of your csv file:

           

          <root>

          <csvfile>C:\ExtractRefresh\flag.csv</csvfile>

          <tableau>

           

            <server>Put the Tableau server name</server>

            <!--This is the tableau server user name and password so we can login to the server>

            <username>Put the Tableau user account username</username>

            <password>Put the Tableau login password</password>

          </tableau>
          </root>

           

           

          And then use the below Powershell script to read the csv file and configuration file and refresh the extract:

           

          param ([string] $config_path = "C:\ExtractRefresh\config.xml")

          [string] $cmddir = "C:\Program Files\Tableau\Tableau Server\9.0\extras\Command Line Utility")

           

          $csvpath = $config_xml.selectsinglenode('/root/csvfile')."#text"

          $csvfile = import-csv -path $csvpath

          $server = $config_xml.selectsinglenode('/root/tableau/server')."#text"

          $username = $config_xml.selectsinglenode('/root/tableau/username')."#text"

          $password = $config_xml.selectsinglenode('/root/tableau/password')."#text"

          foreach ($line in $csvfile)

          {

          $flag= $line.flag

          $extractname= $line.extractname

          if ($flag -eq 1)

          {

              #change directory to Tableau Command Line Utility

              cd $cmddir

              .\tabcmd login -s $server -u $username -p $password

              #Refreshing the extract

           

              $message=.\tabcmd refreshextracts  --datasource $extractname --synchronous

              #Write-Host $message

              if ($message -like '*DataSourceException*')

                  {

                      $status="Extract Refresh Failed"

                      #Write-Host $status

                    

                  }

              else

                  {

           

           

                      $status="Extract Refreshed Successfully"

                      $message="Finished refresh of extract $extractname"

                      #Write-Host $status

                  }

          }

          }

           

          Please modify the script based on your needs.

          1 of 1 people found this helpful
          • 2. Re: Refresh Datasource from tabcmd if a condition is met using batch
            Ashish Singh

            Hi Rishabh,

             

            Thanks a lot for providing the solution. I am going to try the solution after lunch and see if this works.

             

            Ashish

            • 3. Re: Refresh Datasource from tabcmd if a condition is met using batch
              Ashish Singh

              Hi Rishabh,

               

              Even though I was not able to correctly able to edit your PS script (most likely because I am sure I did something wrong), following line in your script

              if ($flag -eq 1)

              ..led me to great insight on how to do this in the batch solution I was working on, and after half an hour of Stackoverflow now I am successfully able to read and parse my csv and able to conditionally refresh my extract.

              Thank you very much for your valuable time for making this great insight available to me.

               

              Cheers!

              Ashish

              • 4. Re: Refresh Datasource from tabcmd if a condition is met using batch
                Rishabh Dhingra

                That's great Ashish, Glad I was able to help a bit