7 Replies Latest reply: Nov 2, 2015 4:17 AM by Øystein Kolsrud RSS

    Qlik Sense: Update a visualization's title via API

    Bill Michielsen

      Qlik Sense 2.1.1 has been integrated with my application. However, our application has dynamically named elements, which happen to appear in the title of several visualizations. Is there any way to programmatically update a visualization's title (or anything else for that matter) via the QRS, Engine, or any other Qlik Sense API? I was thinking I would have some sort of automated process which would scan the visualizations for known placeholders and update them accordingly, but I am lost as to which API has the information and the actions I would need.

       

      Thanks in advance.

        • Re: Qlik Sense: Update a visualization's title via API
          Erik Wetterberg

          Hi Bill,

          The ApplyPatches method in the Engine API allows you to modify visualization properties.

           

          Erik

          • Re: Qlik Sense: Update a visualization's title via API
            Øystein Kolsrud

            Modifying a visualization title is basically an update of the objects properties which implies that you want to use either the ApplyPatch method that Erik Wetterberg mentioned or the SetProperties method of the Engine API.

             

            If you do this through the .Net SDK you can access the data structures of the client visualizations through C# which means you could do something like this where "app" refers to a Qlik Sense app that has been opened, and "sheet" refers to a sheet of that app:

             

            var visualizations = sheet.

              GetChildInfos().

              Select(childInfo => app.GetObject<GenericObject>(childInfo.Id)).

              OfType<IVisualizationBase>();

            foreach (var visualization in visualizations)

            {

              using(visualization.SuspendedLayout)

              {

                visualization.Properties.Title = "My new title";

              }

            }

             

            You can refer to the following page if you want more information concerning how to get started with the .Net SDK:

             

            Building applications with the .NET SDK

             

            The following page contains samples illustrating of how to use the .Net SDK. The sample "App preload" illustrates how to access all objects of an app, while the sample "App traverser" illustrates how to access specific information within different entities of an app:


            Download code samples

              • Re: Qlik Sense: Update a visualization's title via API
                Bill Michielsen

                Thanks Øystein, between your sample and the code samples (I can't believe I never saw that page before) I was able to work it out. I do have a follow-on question though.

                 

                My data model has dynamically named fields in it. Now, I already know I can do a MAPPING LOAD and RENAME FIELDS call in the load script to rename the fields and any visualizations which use that field will automatically have the dimension label updated with the new name (so long as you left it at the default value), but this does not seem to work for filter panes. Is there a similar mechanism with the .NET SDK to be able to change the label of a dimension within a filter pane? The filter pane on the sheet is an extension of a master object, if that makes any difference.

                  • Re: Qlik Sense: Update a visualization's title via API
                    Øystein Kolsrud

                    Filterpanes do actually not contain any dimensions at all. At least not from the Engine perspective. Instead, a filterpane is a container for Listboxes which in turn are the ones that carry the ListObjects that have dimensions. So to modify the dimensions of a filterpane, you need to traverse the children of the filterpane object. So somethings similar to this:

                     

                    var listboxes = filterpane.

                      GetChildInfos().

                      Select(childInfo => app.GetObject<GenericObject>(childInfo.Id)).

                      OfType<IListbox>();

                    foreach (var listobx in listboxes)

                    {

                      using(listbox.SuspendedLayout)

                      {

                        <some operation on the listbox>

                      }

                    }

                      • Re: Qlik Sense: Update a visualization's title via API
                        Bill Michielsen

                        Thanks again Øystein. I am very frustrated by the lack of documentation on the SDK and object structures.

                         

                        Anyways, I am now experimenting with using variables to control the names, rather than having the dynamic pieces hard-coded, since I wouldn't necessarily know which items need to have their titles modified. I figured out how to lookup variables (not script generated) within the app, but I cannot seem to get any updates to stick. Here is what I am doing. Perhaps you can point me in the right direction to be able to update a variables value via the SDK?

                         

                        var v = app.GetVariableByName("VariableName");

                        if (v != null)

                        {

                            v.SetStringValue("New Value");

                        }

                          • Re: Qlik Sense: Update a visualization's title via API
                            Øystein Kolsrud

                            The SDK reference documentation for the GenericVariable class has been improved since last release, and will be better for the next release of Qlik Sense. The engine API documentation has some more information on that class though (which is the information we have extracted to the SDK reference as well). In particular that documentation states that the settings you do with "SetStringValue" are not persisted, which is probably why you see the behavior you are seeing:

                             

                            GenericVariable.SetStringValue

                             

                            You probably need to update the properties of the variable to achieve what you want. I would assume what you are looking for is something like this:

                             

                            var v = app.GetVariableByName("VariableName");

                            if (v != null)

                            {

                              var props = v.Properties;

                              props.Definition = "New Value";

                              v.SetProperties(props);

                            }


                            Note, however,that you cannot update the properties of a script-defined variable.


                            GenericVariable.SetProperties

                    • Re: Qlik Sense: Update a visualization's title via API
                      Øystein Kolsrud

                      I hope you have been able to achieve what you were trying to do. Please also mark the an answer as "Correct" if you feel you have the information you need.

                       

                      Best regards, Øystein