2 Replies Latest reply: May 12, 2017 11:01 AM by Fabio Cavallari RSS

    Qlik Sense custom connector and QVX SDK 2.1

    Fabio Cavallari

      I am working on a custom connector for Qlik Sense and I am using the QVX SDK 2.1 64bit version.

      I starded from this document: https://help.qlik.com/en-US/sense-developer/2.2/Subsystems/QVXSDKAPI/Content/Introducing-QVX.htm

      but i have a lot of problem with the Qlik Sense adaptation: https://help.qlik.com/en-US/sense-developer/2.2/Subsystems/QVXSDKAPI/Content/QlikSense-adaptation.htm

       

      The most important problem is that:

      when I submit the form with details for connection (file connectdialog.js) and i call function input.serverside.createNewConnection the QRS don't save all info about the connection and if I edit it I loose all value for all fields.

       

      Can somebody help me with some examples or some articles that may take me on the right way?

       

      Thanks.

        • Re: Qlik Sense custom connector and QVX SDK 2.1
          Michael Goichmann

          Hi Fabio,

           

          Did you find any ways to solve your task ?

          If you have now an example of custom connector, please send it to me.

           

          BR,

          Michael

            • Re: Qlik Sense custom connector and QVX SDK 2.1
              Fabio Cavallari

              Sorry, i read this a bit late... anyway it can helps someone.

              Qlik Sense persists only the connection string that user creates when add or edit a connection in Sense, so if you want some custom parameters you have to add them in the connection string.

               

              I attached my connectdialog.js file.

              If you want to pass your custom parameters you have to add them to your connection string (in the connectdialog.js) file (in the example my custom parameter is: 'ws_url'):

               

              $scope.connectionString = createCustomConnectionString($scope.provider, "host=xxx;ws_url=" + $scope.webserviceurl + ";");
              
              

               

              When you implement the QvxConnection base class of the QVX SDK you can get your parameter from connection string using 'MParameters.TryGetValue(string, out string)' method. In my case:

               

                private void getParametersFromConnection()
                      {
                          this.MParameters.TryGetValue("ws_Url", out webServiceUri);
                          this.MParameters.TryGetValue("ws_Username", out webServiceUsername);
                          this.MParameters.TryGetValue("ws_AccessKey", out webServiceAccessKey);
                      }
              
              

               

              I call this when Connector has to initialize the connection in QvxConnection class (the sample below contains the relevant part of the connector):

               

                public sealed class QvConnection : QlikView.Qvx.QvxLibrary.QvxConnection
                  {
                      string webServiceUri;
                      string webServiceUsername;
                      string webServiceAccessKey;
                     
                      public override void Init()
                      { 
                          QvxLog.SetLogLevels(true, true);
                          QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Debug, "QvxConnection.Init()");
              
                          // Get parameters from connection string
                          getParametersFromConnection();
              
                          // Create 'MyTable' QvxTable.
                          createTable();
                   
                          // Create all QvxTables from all tables.
                          createQvxTables();     
                      }
              
                  void createTable()
                      {
                          var fields = new QvxField[]
                             {
                              new QvxField("Name", QvxFieldType.QVX_TEXT, QvxNullRepresentation.QVX_NULL_FLAG_SUPPRESS_DATA, FieldAttrType.ASCII),
                              new QvxField("Label", QvxFieldType.QVX_TEXT, QvxNullRepresentation.QVX_NULL_FLAG_SUPPRESS_DATA, FieldAttrType.ASCII),
                              new QvxField("EntityType", QvxFieldType.QVX_TEXT, QvxNullRepresentation.QVX_NULL_FLAG_SUPPRESS_DATA, FieldAttrType.ASCII),
                              new QvxField("Singular", QvxFieldType.QVX_TEXT, QvxNullRepresentation.QVX_NULL_FLAG_SUPPRESS_DATA, FieldAttrType.ASCII)
                             };
              
                          MTables = new List<QvxTable> {
                                  new QvxTable {
                                      TableName = "MyTable",
                                      GetRows = myTableRowsHandler,
                                      Fields = fields
                                  }
                              };
                      }
              
                      IEnumerable<QvxDataRow> myTableRowsHandler()
                      {
                          QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Notice, "GetRowsHandler()");
              
                          var values = <get your list of data>
                          foreach (var val in values)
                          {
                              yield return MakeRow(val, FindTable("MyTable", MTables));
                          }
                      }
              
                      QvxDataRow MakeRow(object obj, QvxTable table)
                      {
                          QvxDataRow row = new QvxDataRow();
              
              
                          row[table.Fields[0]] = obj.Name;
                          row[table.Fields[1]] = obj.Label;
                          row[table.Fields[2]] = obj.EntityType;
                          row[table.Fields[3]] = obj.Singular;
                          return row;
                      }
              
              [...]
              }
              
              

               

              I hope it can help someone.