4 Replies Latest reply on Nov 28, 2017 7:06 AM by Jason McCann

    Web Data Connector using SOAP request

    Jason McCann

      Hello all,

       

      Admittedly, I'm a novice when it comes to JavaScript, web service requests and the Tableau Web Data Connector (the perfect storm, really).

      What I'm trying to do:  Build a WDC that allows a user to enter a product number.  The WDC returns inventory information on that product number via SOAP request to an internal web service.

       

      What I've done: Built the page that prompts user for product number.  The Connection Name and Connection Data does appear when testing in the WDC Simulator 2.0.

       

      What I'm stuck on:  Building the SOAP request.  I've been provided with a sample request from the web service:

       

      POST /PricingInventory/GetPricingAndInventory.asmx HTTP/1.1

      Host: ws.mywebservice.com

      Content-Type: text/xml; charset=utf-8

      Content-Length: length

      SOAPAction: "http://ws.mywebservice.com/PricingInventory/GetWarehouseInventoriesAndAtpDetails"

       

      <?xml version="1.0" encoding="utf-8"?>

      <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">

        <soap:Body>

         <GetWarehouseInventoriesAndAtpDetails xmlns="http://ws.mywebservice.com/PricingInventory">

          <requests>

           <AtpRequest>

            <Warehouse>string</Warehouse>

            <PartNumber>string</PartNumber>

            <Quantity>int</Quantity>

            <DeliveryDate>dateTime</DeliveryDate>

            <CompanyName>string</CompanyName>

           </AtpRequest>

         </GetWarehouseInventoriesAndAtpDetails>

        </soap:Body>

      </soap:Envelope>

       

      Connector.html

      <html>

       

       

      <head>

          <title>Warehouse Inventory Request</title>

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

       

       

          <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" crossorigin="anonymous">

          <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js" type="text/javascript"></script>

          <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" crossorigin="anonymous"></script>

       

       

          <script src="https://connectors.tableau.com/libs/tableauwdc-2.1.latest.js" type="text/javascript"></script>

          <script src="ATPConnector.js" type="text/javascript"></script>

      </head>

       

       

      <body>

        <p>Enter a part number: <input type="text" id="partNumber" /></p>

        <p><button type="button" id="submitButton">Get Data</button></p>

      </body>

       

       

      </html>

       

      My current Connector.js (doesn't work, but this is the direction I'm heading):

       

      (function () {

          var myConnector = tableau.makeConnector();

       

       

          myConnector.getSchema = function (schemaCallback) {

        var cols = [

        {id: "warehouse", alias: "Warehouse", dataType : tableau.datatTypeEnum.string},

        {id: "partnumber", alias: "PartNumber", dataType : tableau.datatTypeEnum.string},

        {id: "QuantityOnDeliveryDate", alias: "QuantityOnDeliveryDate", dataType : tableau.datatTypeEnum.int},

        {id: "DeliveryDate", alias: "DeliveryDate", dataType : tableau.datatTypeEnum.date},

        {id: "CompanyNumber", alias: "CompanyNumber", dataType : tableau.datatTypeEnum.int},

        {id: "QuantityRequested", alias: "QuantityRequested", dataType : tableau.datatTypeEnum.int}

        ];

       

        var tableInfo = {

        id: "AtpResponseDetails",

        alias: "AtpResponseDetails",

        columns: cols

        };

        schemaCallback([tableInfo]);

          };

       

       

          myConnector.getData = function (table, doneCallback) {

        $.soap({

        url: 'http://ws.mywebservice.com/PricingInventory/'

        method: 'GetPricingAndInventory.asmx'

       

        data: {

        Warehouse = '555911',

        PartNumber = 'MG725',

        Quantity = 2000,

        CompanyName = "UnitedStates"

        };

       

        success: function (soapResponse.toString()) {

       

       

        },

        error: function (SOAPResponse) {

        //show error

        }

       

        })

       

          };

       

       

          tableau.registerConnector(myConnector);

       

        $(document).ready(function() {

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

            var partNum = $('#partNumber').val().trim();

            if (partNum) {

              tableau.connectionName = "Data for " + partNum;

              tableau.connectionData = partNum;

              tableau.submit();

            }

          });

        });

       

      })();

       

       

       

       

      Any help is much appreciated!