2 Replies Latest reply: Jun 17, 2016 2:21 AM by Alex Watts RSS

    GetAppFields() returns different field names each time its called

    Alex Watts

      Hi All,

       

      I'm pretty new to Qlik Development, so It's very possible that this is happening because I am doing something wrong. I built a WPF app which displays a Sheet in a WebBrowser control and I have buttons that I use to make selections, clear selections or get debug info. I found some odd behaviour when trying to make selections based on a field name, so I tried to debug it. I have the below code which is triggered by a button press. It uses the Helpdesk Management app, gets all field names and the first 5 values for each field, then displays all this info in a TextBox.

       

      SERVERSIDE CODE (on button click)

      // Single Qlik Sense Desktop with no special settings

      var qlikLoc = Location.FromUri(new Uri("ws://127.0.0.1:4848"));

      // Defining the location as a direct connection to Qlik Sense Personal

      qlikLoc.AsDirectConnectionToPersonalEdition();

      IAppIdentifier foundAppIdentifier = qlikLoc.AppWithNameOrDefault("Helpdesk Management");

       

      StringBuilder textSB = new StringBuilder(); // hold the data for output

      using (IApp application = qlikLoc.App(foundAppIdentifier))

      {

      textSB.AppendLine("==== FIELDS ====");

      var fields = application.GetAppFields();

      foreach (var field in fields)

      {

      textSB.AppendLine("Field Name: '" + field.Name + "'");

      var p = new List<NxPage> { new NxPage { Height = 5, Width = 1 } };

      var dataPages = field.GetData(p);

      foreach (var dataPage in dataPages)

      {

      var matrix = dataPage.Matrix;

      foreach (var cellRows in matrix)

      {

      foreach (var cellRow in cellRows)

      {

      textSB.AppendLine("\t[" + cellRow.ElemNumber + "] " + cellRow.Text + " - " + cellRow.State);

      }

      }

      }

      }

      }

      tbData.Text = textSB.ToString(); // tbData is a TextBox control on my WPF app

       

      If i use the very first field, %CaseId, as an example I get the following output, the first time I press the button.

       

      OUTPUT

      Field Name: '%CaseId'

      [0] ABC112233445567050 - OPTION

      [1] ABC112233445567059 - OPTION

      [2] ABC112233445567068 - OPTION

      [3] ABC112233445567077 - OPTION

      [4] ABC112233445567086 - OPTION

       

      If I then press it again I get a different field name, this time i get a guid as the field name instead of the actual field name, %CaseId

       

      OUTPUT

      Field Name: 'd253d3f0-d190-4344-881e-1d10c061f824'

      [0] ABC112233445567050 - OPTION

      [1] ABC112233445567059 - OPTION

      [2] ABC112233445567068 - OPTION

      [3] ABC112233445567077 - OPTION

      [4] ABC112233445567086 - OPTION

       

      If I then again press the button I get another different guid, and so on and so forth.

       

      So I have 2 questions:

      1. Why does the field name change every time I call GetAppFields()
      2. Is this the best way to get values for a field.

       

      I am using Qlik Sense desktop for my example, below is the version and build I am using in case you needed that info.

      2016-06-16 10_11_46-Qlik Sense Desktop.png

       

      Many thanks in advance.

       

      Alex Watts

        • Re: GetAppFields() returns different field names each time its called
          Øystein Kolsrud

          The fact that you get GUID the second time you do the selection stems from the fact that when you do "GetAppField" you actually create a new generic object that contains a list object that retrieves the values of the field for you. The first time, you call "GetAppField" it will use the field name as the ID, but the second time it can't since an object with that ID already exists. So the engine simply ignores the ID the SDK provides and makes up it's own unique ID.

           

          On option in your case would be to not create a new app field every time, but simply keep the app filed you retrieved the first time.

           

          For your second question: please refer to the answer I posted on your other thread. Re: Engine API select range in .NET application

            • Re: GetAppFields() returns different field names each time its called
              Alex Watts

              Thanks for the reply. I was able to use you advice here and on the other question to "fix" my problem. FYI I did try to store the GetAppField() return in a class variable (qlikAppFields) but I kept getting an error the second time I tried to access qlikAppFields. Which is understandable, well sort of. I'm guessing since App was disposed of qlikAppFields was no longer valid. I don't know either way here is my that was consistent each time:

               

              var fieldCounter = 0;
              var fieldList = qlikApplication.GetFieldList();
              foreach(var field in fieldList.Items)
              {
                   fieldCounter++;
                   // stringbuilder
                   textSB.AppendLine(string.Format("Field: [{0}] {1}", fieldCounter, field.Name));
                   var p = new List { new NxPage { Height = 5, Width = 1 } };
                   var appField = qlikApplication.GetAppField(field.Name);
                   var dataPages = appField.GetData(p);
                   foreach (var dataPage in dataPages)
                   {
                        var matrix = dataPage.Matrix;
                        foreach (var cellRows in matrix)
                        {
                             foreach (var cellRow in cellRows)
                             {
                                  textSB.AppendLine(
                                       "  [" + cellRow.ElemNumber + "]\t" 
                                       + cellRow.Text + " - " 
                                       + cellRow.State);
                             }
                        }
                   }
                   if (fieldCounter == 5){
                        break;
                   }
              }