2 Replies Latest reply on Jun 16, 2017 3:26 PM by Ed is Awesome Bynum

    Uncaught Looks like the WDC is calling a tableau function before tableau.init() has been called.

    Ryan Quejano

      Hi,

       

      I'm encountering this error when I tried to to run my Web Data Connector below. Can anyone give some pointers? Thank you.

       

      <html>

      <meta http-equiv="Cache-Control" content="no-store" />

      <head>

      <title>ODataConnector</title>

      <script

          src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"

          type="text/javascript"></script>

      <script

          src="https://public.tableau.com/javascripts/api/tableauwdc-1.1.0.js"

          type="text/javascript"></script>

      <script type="text/javascript">

          (function() {

             

              var myConnector = tableau.makeConnector();

       

              function buildUrl(mandt, uname, pword, ebeln, ebelp) {

                  var url;

                  var cond;

                  var data = '?client=' + mandt + '&language=EN&user='

                          + uname + '&password=' + pword + '&$format=json';

                  if (ebeln) {

                      cond = "(Ebeln='" + ebeln + "',Ebelp='" + ebelp + "')";

                  }

                  if (cond) {

                      url = "http://<server>/sap/opu/odata/sap/ZGW_ORDERS_SRV/POItemSet"

                              + cond + data;

                  } else {

                      url = "http://<server>/sap/opu/odata/sap/ZGW_ORDERS_SRV/POItemSet"

                              + data;

                  }

                  return url;

              }

              ;

       

              myConnector.getColumnHeaders = function() {

                  var fieldNames = [ 'Ebeln', 'Ebelp', 'Matnr', 'Werks', 'Lgort',

                                     'Matkl', 'Menge', 'Meins' ];

                  var fieldTypes = [ 'string', 'string', 'string', 'string',

                                     'string', 'string', 'string', 'string' ];

                  tableau.headersCallback(fieldNames, fieldTypes);

              };

             

              myConnector.getTableData = function(lastRecordToken) {

                  var connectionData = JSON.parse(tableau.connectionData);

                  var mandt = connectionData["mandt"];

                  var uname = connectionData["uname"];

                  var pword = connectionData["pword"];

                  var ebeln = connectionData["ebeln"];

                  var ebelp = connectionData["ebelp"];

       

                  var connectionUrl = buildUrl(mandt, uname, pword, ebeln, ebelp);

                  var xhr = $.ajax({

                      url : connectionUrl,

                      dataType : 'json',

                      success : function(data) {

                          if (data.query.results) {

                              var quotes = data.query.results.quote;

                              var ii;

                              var toRet = [];

       

                              for (ii = 0; ii < quotes.length; ++ii) {

                                  var entry = {

                                      'Ebeln' : quotes[ii].Ebeln,

                                      'Ebelp' : quotes[ii].Ebelp,

                                      'Matnr' : quotes[ii].Matnr,

                                      'Werks' : quotes[ii].Werks,

                                      'Lgort' : quotes[ii].Lgort,

                                      'Matkl' : quotes[ii].Matkl,

                                      'Menge' : quotes[ii].Menge,

                                      'Meins' : quotes[ii].Meins

                                  };

                                  toRet.push(entry);

                              }

                               tableau.dataCallback(toRet, toRet.length.toString(), false);

                          } else {

                              tableau.abortWithError('No results found!');

                          }

                      },

                      error : function(xhr, ajaxOptions, thrownError) {

                          tableau.log('Connection error: ' + xhr.responseText + '\n'

                                  + thrownError);

                          tableau.abortWithError('Error connecting to SAP');

                      }

                  });

       

              };

       

              myConnector.setTicker = function(mandt, uname, pword, ebeln, ebelp) {

                  var connectionData = {

                      "mandt" : mandt,

                      "uname" : uname,

                      "pword" : pword,

                      "ebeln" : ebeln,

                      "ebelp" : ebelp

                  }

                  tableau.connectionData = JSON.stringify(connectionData);

                  tableau.connectionName = 'Get PO Items ' + ebeln;

              };

       

                                   tableau.registerConnector(myConnector);

       

              $(document).ready(function() {

                  $("#submitButton").click(function() {

                      var mandt = $('#mandt').val().trim();

                      var uname = $('#uname').val().trim();

                      var pword = $('#pword').val().trim();

                      var ebeln = $('#ebeln').val().trim();

                      var ebelp = $('#ebelp').val().trim();

                      if (mandt) {

                          myConnector.setTicker(mandt, uname, pword, ebeln, ebelp);

                                                                               tableau.submit();

                      }

                  });

              });

          })();

      </script>

      </head>

      <body>

          Client

          <span style="padding-left: 22px;"></span>:

          <input type='text' id='mandt' style='width: 30px;' required />

          <br> Username:

          <input type='text' id='uname' style='width: 100px;' required />

          <br> Password

          <span style="padding-left: .1px;"></span>:

          <input type='text' id='pword' style='width: 100px;' required />

          <br>

          <br> Document No.:

          <input type='text' id='ebeln' style='width: 100px;' />

          <br> Item No.

          <span style="padding-left: 33px;"></span>:

          <input type='text' id='ebelp' style='width: 50px;' />

          <br>

          <br>

          <button type='button' id='submitButton'>Get PO Items</button>

      </body>

      </html>