3 Replies Latest reply: Feb 4, 2016 12:19 AM by Andy Lin RSS

    Qlik Sense: How to set Bookmark selection fields and send user to bookmark

      My overall goal is to do this:

      1) Using .Net scripting, create a new bookmark with a filter determined from the .Net app

      2) Send a user's browser to that bookmark.

       

      Below is my code related to creating a bookmark.   It works, except I have not been able to successfully create an expression for bookmarkProperties.SelectionFields.Where().  In my case, I want to create a filter WHERE <column name> = <value>

       

      Regarding item #2, I am using code like this -- I am not clear how I would direct the browser to a specific bookmark.

           String webAddress = "https://<Server>/sense/app/<AppID>/sheet/<SheetID>";

           Process.Start(webAddress);

       

       

      Thank you

       

      using System;

      using System.Collections.Generic;

      using System.ComponentModel;

      using System.Data;

      using System.Drawing;

      using System.Linq;

      using System.Linq.Expressions;

      using System.Text;

      using System.Threading.Tasks;

      using System.Windows.Forms;

      using Qlik.Engine;

      using Qlik.Sense.Client;

       

                  System.Uri qlikURI = new System.Uri("https://<Server Name>/");

                  ILocation location = Qlik.Engine.Location.FromUri(qlikURI);

                  using (IHub hub = location.Hub())

                  {

                      IAppIdentifier appID = location.AppWithName("<App Name");

                      IApp application = location.App(appID);

                      IEnumerable<ISheet> sheets = application.GetSheets();             

                      ISheet thisSheet = null;

                      IBookmark bookmark = null;

                      foreach (ISheet activeSheet in sheets)

                      {

                          if (activeSheet.SheetMetaData.Title == "<Sheet Name>") {

                              thisSheet = activeSheet;

                          }                 

                      }                                             

                      if (thisSheet != null) {                   

                          Qlik.Sense.Client.BookmarkProperties bookmarkProperties = new BookmarkProperties();

                          bookmarkProperties.SheetId = thisSheet.Id;

                          bookmarkProperties.Title = "New Bookmark";

                          bookmarkProperties.CreationDate = "1/1/2014";                 

                          //bookmarkProperties.SelectionFields.Where();

                          bookmark = application.CreateBookmark("New Bookmark 1",bookmarkProperties);                                 

                      }

                  }

        • Re: Qlik Sense: How to set Bookmark selection fields and send user to bookmark

          I would first ask you to use lists instead of instances of objects, that way you can read the properties of generic objects before you instantiate them.

           

          Example for sheetList:

          ISheetList sheetList = application.GetSheetList();
          foreach (ISheetObjectViewListContainer item in sheetList.Items)
          {
              Console.WriteLine(item.Data.Title);
          }
          
          
          
          
          
          
          
          
          
          
          
          
          
          
          

           

          This doesn't solve your problems but will make your program faster, and you can react on changes in the lists.

           

          https://help.qlik.com/sense/en-us/developer/index.html#../Subsystems/NetSdk/Content/HowTos/NetSdk_HowTo_ListSheets.htm%3…

           

          To create a Bookmark that reflects an application selection state you need to set the selection state before you create the bookamark.

           

              System.Uri qlikURI = new System.Uri("https://<Server Name>/");
              ILocation location = Location.FromUri(qlikURI);
              IAppIdentifier appID = location.AppWithName("<App Name>");
          
              using (IApp application = location.App(appID))
              {
                  ISheetList sheetlist = application.GetSheetList();
                  ISheet thisSheet = sheetlist.Items
                        .First(o => o.Data.Title.Equals("<Sheet Name>"))
                        .As<Sheet>();
          
                  IAppField field1 = application.GetAppField("<Field1>");
                  field1.SelectAll();
          
                  IAppField field2 = application.GetAppField("<Field2>");
                  field2.SelectValues(new[] { 1, 45, 77 }, toggleMode: false, softLock: false);
          
                  var bookmarkProperties = new BookmarkProperties
                  {
                      SheetId = thisSheet.Id,
                      Title = "New Bookmark",
                      CreationDate = "2014-10-07T19:43:16.523Z",
                      SelectionFields = "<Field1>, <Field2>"
                  };
                  var bookmark = application.CreateBookmark("<Bookmark1>", bookmarkProperties);
              }
          
          
          
          
          
          
          
          
          
          
          
          
          

           

          The SelectionFields Property is a comma separated string with the Fields used in the bookmark, this is mainly used to show information in the Qlik Sense client.

           

          A solution to your second question is currently not supported, but could be emulated using extensions.

           

          define(["jquery","qlik"], function($, qlik) {
            paint : function() {
               qlik.currApp().bookmark.apply("<Bookmark1>");
            }
          });
          
          
          

           

          Please see the Toolbar Extension Example for more information, https://help.qlik.com/sense/en-us/developer/index.html#../Subsystems/Workbench/Content/CodeExamples/ext_toolbar.htm%3FTo…

           

          Regards,

          Johan Tejle

          • Re: Qlik Sense: How to set Bookmark selection fields and send user to bookmark
            Andy Lin

            I am trying to accomplish the same thing.  Can you share if you are able to send user directly to the bookmark via URL?