<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Export data from bookmark using NodeJS script in Integration, Extension &amp; APIs</title>
    <link>https://community.qlik.com/t5/Integration-Extension-APIs/Export-data-from-bookmark-using-NodeJS-script/m-p/1780746#M13802</link>
    <description>&lt;P&gt;It works as you do it but you will get one exported file per bookmark. Not sure that's what you want or you want to combine them all?&lt;BR /&gt;&lt;BR /&gt;You can create a Listbox with the field that you are interested in and iterate over the bookmarks and retrieving the values (e.g selected and possible) from the Listbox&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const listObjectProps = {
  qInfo: {
    qType: "my-list-object"
  },
  qListObjectDef: {
    qDef: {
      qFieldDefs: ["&amp;lt;FIELD_NAME&amp;gt;"]
    },
    qInitialDataFetch: [
      {
        qTop: 0,
        qHeight: 100,
        qLeft: 0,
        qWidth: 1
      }
    ]
  }
};

const getValuesFromBookmark = async (filteredBookmarks, app) =&amp;gt; {
  const listbox = await app.createSessionObject(listObjectProps);
  var allSelectedValues = [];

  for (const bookmark of filteredBookmarks) {
    await app.applyBookmark(bookmark.qInfo.qId);
    const listBoxLayout = await listbox.getLayout();
    const values = listBoxLayout.qListObject.qDataPages[0].qMatrix;

    for (const value of values) {
      if (value[0].qState === "S" || value[0].qState === "O") {
        const elemNum = value[0].qElemNumber;
        const allready = allSelectedValues.some((v) =&amp;gt; v["qElemNumber"] === elemNum);)
          if (!allready) {
            allSelectedValues.push(value)
          }
      }
    }
  }

  return allSelectedValues.flat();
};

// ==== And call it
   const v = await getValuesFromBookmark(filteredBookmarks, app)
   console.log(v)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The maximum number of rows possible to fetch at once is 10000 soo if your field contains more values you have to implement pagination. Maybe it's possible to only get the selectedvalues in the response (have checked the props of the listbox)&lt;/P&gt;</description>
    <pubDate>Mon, 08 Feb 2021 08:14:15 GMT</pubDate>
    <dc:creator>han</dc:creator>
    <dc:date>2021-02-08T08:14:15Z</dc:date>
    <item>
      <title>Export data from bookmark using NodeJS script</title>
      <link>https://community.qlik.com/t5/Integration-Extension-APIs/Export-data-from-bookmark-using-NodeJS-script/m-p/1778883#M13780</link>
      <description>&lt;P&gt;Hi!&lt;/P&gt;
&lt;P&gt;I would like to export data selected by a bookmark in a certain application to be exported using a NodeJS script running on some server. Is this possible? The end goal here is to (semi-)automate a user segmentation process.&lt;BR /&gt;I can connect using Node and Enigma.js and list various things, but I am not sure if I can get a selection from a bookmark using Enigma. Or can I talk to the Capability API directly somehow?&lt;/P&gt;
&lt;P&gt;Another possibility would be to write some kind of component that runs as an extension within the application, that the QlikSense user can click to automatically export the data somehow, but I would prefer the NodeJS solution if possible, as it would integrate better with our other systems.&lt;/P&gt;</description>
      <pubDate>Fri, 13 Aug 2021 18:57:10 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Integration-Extension-APIs/Export-data-from-bookmark-using-NodeJS-script/m-p/1778883#M13780</guid>
      <dc:creator>fluxfrog</dc:creator>
      <dc:date>2021-08-13T18:57:10Z</dc:date>
    </item>
    <item>
      <title>Re: Export data from bookmark using NodeJS script</title>
      <link>https://community.qlik.com/t5/Integration-Extension-APIs/Export-data-from-bookmark-using-NodeJS-script/m-p/1778928#M13781</link>
      <description>&lt;P&gt;What would you like the outcome to be?&lt;BR /&gt;Do you want the selected values that the bookmark will apply or do you want the "datamodel" that the bookmark will produce?&lt;/P&gt;&lt;P&gt;&lt;A href="https://qlik.dev/apis/json-rpc/qix/doc#%23%2Fentries%2FDoc%2Fentries%2FApplyBookmark" target="_blank" rel="noopener"&gt;https://qlik.dev/apis/json-rpc/qix/doc#%23%2Fentries%2FDoc%2Fentries%2FApplyBookmark&lt;/A&gt;&amp;nbsp;if you want to apply/"use" the bookmark&lt;/P&gt;</description>
      <pubDate>Mon, 01 Feb 2021 19:22:03 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Integration-Extension-APIs/Export-data-from-bookmark-using-NodeJS-script/m-p/1778928#M13781</guid>
      <dc:creator>han</dc:creator>
      <dc:date>2021-02-01T19:22:03Z</dc:date>
    </item>
    <item>
      <title>Re: Export data from bookmark using NodeJS script</title>
      <link>https://community.qlik.com/t5/Integration-Extension-APIs/Export-data-from-bookmark-using-NodeJS-script/m-p/1778957#M13782</link>
      <description>&lt;P&gt;Hi!&lt;/P&gt;&lt;P&gt;I would like my Qlik Sense users to be able to create customer segments using bookmarks in a certain application (to identify some group of customers). Then, I would like my script to look at these bookmarks, and write a text file containing the customer numbers for all these customers every night, or something like that.&lt;/P&gt;</description>
      <pubDate>Mon, 01 Feb 2021 14:12:39 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Integration-Extension-APIs/Export-data-from-bookmark-using-NodeJS-script/m-p/1778957#M13782</guid>
      <dc:creator>fluxfrog</dc:creator>
      <dc:date>2021-02-01T14:12:39Z</dc:date>
    </item>
    <item>
      <title>Re: Export data from bookmark using NodeJS script</title>
      <link>https://community.qlik.com/t5/Integration-Extension-APIs/Export-data-from-bookmark-using-NodeJS-script/m-p/1779089#M13783</link>
      <description>&lt;P&gt;It should be possible to have them publish bookmarks with some name convention soo that your script could find the bookmark and apply it. And after that grab the selected values from some field.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But I guess it would be a nicer experience for the users if you just make an extension that will post the values from a field to an internal server.&lt;BR /&gt;&lt;BR /&gt;Long time since I did an extension but it should be pretty easy to make&lt;/P&gt;</description>
      <pubDate>Mon, 01 Feb 2021 19:26:35 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Integration-Extension-APIs/Export-data-from-bookmark-using-NodeJS-script/m-p/1779089#M13783</guid>
      <dc:creator>han</dc:creator>
      <dc:date>2021-02-01T19:26:35Z</dc:date>
    </item>
    <item>
      <title>Re: Export data from bookmark using NodeJS script</title>
      <link>https://community.qlik.com/t5/Integration-Extension-APIs/Export-data-from-bookmark-using-NodeJS-script/m-p/1779094#M13784</link>
      <description>&lt;P&gt;I see your point, but for various reasons, I think the naming convention would be the best way here. However, what I don't understand is how I can use Enigma.js to achieve this. I can't find any examples of anything like this.&lt;/P&gt;&lt;P&gt;I have found a bunch of examples of have to use the Capability API, but that is always in the context of some frontend code, and I don't know how to translate that to anything that can be run in a NodeJS script on my servers.&lt;/P&gt;</description>
      <pubDate>Mon, 01 Feb 2021 19:43:24 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Integration-Extension-APIs/Export-data-from-bookmark-using-NodeJS-script/m-p/1779094#M13784</guid>
      <dc:creator>fluxfrog</dc:creator>
      <dc:date>2021-02-01T19:43:24Z</dc:date>
    </item>
    <item>
      <title>Re: Export data from bookmark using NodeJS script</title>
      <link>https://community.qlik.com/t5/Integration-Extension-APIs/Export-data-from-bookmark-using-NodeJS-script/m-p/1779969#M13790</link>
      <description>&lt;P&gt;Hopefully, this could be a start&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const enigma = require("enigma.js");
const schema = require("enigma.js/schemas/12.612.0.json");

const bookmarkListProps = {
  qInfo: {
    qId: "BookmarkList",
    qType: "BookmarkList"
  },
  qBookmarkListDef: {
    qType: "bookmark",
    qData: {
      // dynamic data stored by the Qlik Sense client
      title: "/qMetaDef/title",
      description: "/qMetaDef/description",
      sheetId: "/sheetId",
      selectionFields: "/selectionFields",
      creationDate: "/creationDate"
    }
  }
};

(async () =&amp;gt; {
  const session = enigma.create(&amp;lt;ENIGMA CONFIG&amp;gt;);
  const global = await session.open();
  const app = await global.openDoc(&amp;lt;APP_ID&amp;gt;);

  // creates a session object
  const bookmarkListModel = await app.createSessionObject(bookmarkListProps);
  const bookmarkListLayout = await bookmarkListModel.getLayout();
  const bookmarks = bookmarkListLayout.qBookmarkList.qItems;

  var filteredBookmarks = bookmarks.filter(function (item) {
    return item.qMeta.published &amp;amp;&amp;amp;            // Check if Bookmark is published
           item.qMeta.title.includes("Book")  // And contains a name "pattern"
  });

  console.log(filteredBookmarks);
  // Iterate over the items: apply bookmark and fetch values from field
})()
  .catch((err) =&amp;gt; {
    console.error("ERR:", err);
  })
  .finally(() =&amp;gt; {
    //session.close();
  });&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Feb 2021 20:58:52 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Integration-Extension-APIs/Export-data-from-bookmark-using-NodeJS-script/m-p/1779969#M13790</guid>
      <dc:creator>han</dc:creator>
      <dc:date>2021-02-03T20:58:52Z</dc:date>
    </item>
    <item>
      <title>Re: Export data from bookmark using NodeJS script</title>
      <link>https://community.qlik.com/t5/Integration-Extension-APIs/Export-data-from-bookmark-using-NodeJS-script/m-p/1780067#M13791</link>
      <description>&lt;P&gt;Thanks a lot!&lt;/P&gt;&lt;P&gt;That will work great for my purpose, but I still can't find a lot of information about how to actually retrieve the selected data in the script. The examples seems to always be about doing stuff in the browser, like selecting fields and applying bookmarks, so I'm still unsure about where to find more about this part:&lt;/P&gt;&lt;P&gt;&lt;FONT face="andale mono,times"&gt;// Iterate over the items: apply bookmark and fetch values from field&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Feb 2021 08:09:34 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Integration-Extension-APIs/Export-data-from-bookmark-using-NodeJS-script/m-p/1780067#M13791</guid>
      <dc:creator>fluxfrog</dc:creator>
      <dc:date>2021-02-04T08:09:34Z</dc:date>
    </item>
    <item>
      <title>Re: Export data from bookmark using NodeJS script</title>
      <link>https://community.qlik.com/t5/Integration-Extension-APIs/Export-data-from-bookmark-using-NodeJS-script/m-p/1780129#M13793</link>
      <description>&lt;P&gt;Actually, I now managed to do this:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;  app.applyBookmark('394db859-58d1-4fbf-89e2-321d219f480e');
  let qObj = await app.getObject("mwEZnM");
  const dataExport = await qObj.exportData("OOXML");
  let downloadLink = `https://my.server.url${dataExport.qUrl}`;&lt;/LI-CODE&gt;&lt;P&gt;That produces an url that I can use to get the data directly from a list in the application with the bookmark applied. Great success! Thanks again. Is this the way to do it? Our would there be a better solution?&lt;/P&gt;</description>
      <pubDate>Thu, 04 Feb 2021 11:32:14 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Integration-Extension-APIs/Export-data-from-bookmark-using-NodeJS-script/m-p/1780129#M13793</guid>
      <dc:creator>fluxfrog</dc:creator>
      <dc:date>2021-02-04T11:32:14Z</dc:date>
    </item>
    <item>
      <title>Re: Export data from bookmark using NodeJS script</title>
      <link>https://community.qlik.com/t5/Integration-Extension-APIs/Export-data-from-bookmark-using-NodeJS-script/m-p/1780746#M13802</link>
      <description>&lt;P&gt;It works as you do it but you will get one exported file per bookmark. Not sure that's what you want or you want to combine them all?&lt;BR /&gt;&lt;BR /&gt;You can create a Listbox with the field that you are interested in and iterate over the bookmarks and retrieving the values (e.g selected and possible) from the Listbox&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const listObjectProps = {
  qInfo: {
    qType: "my-list-object"
  },
  qListObjectDef: {
    qDef: {
      qFieldDefs: ["&amp;lt;FIELD_NAME&amp;gt;"]
    },
    qInitialDataFetch: [
      {
        qTop: 0,
        qHeight: 100,
        qLeft: 0,
        qWidth: 1
      }
    ]
  }
};

const getValuesFromBookmark = async (filteredBookmarks, app) =&amp;gt; {
  const listbox = await app.createSessionObject(listObjectProps);
  var allSelectedValues = [];

  for (const bookmark of filteredBookmarks) {
    await app.applyBookmark(bookmark.qInfo.qId);
    const listBoxLayout = await listbox.getLayout();
    const values = listBoxLayout.qListObject.qDataPages[0].qMatrix;

    for (const value of values) {
      if (value[0].qState === "S" || value[0].qState === "O") {
        const elemNum = value[0].qElemNumber;
        const allready = allSelectedValues.some((v) =&amp;gt; v["qElemNumber"] === elemNum);)
          if (!allready) {
            allSelectedValues.push(value)
          }
      }
    }
  }

  return allSelectedValues.flat();
};

// ==== And call it
   const v = await getValuesFromBookmark(filteredBookmarks, app)
   console.log(v)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The maximum number of rows possible to fetch at once is 10000 soo if your field contains more values you have to implement pagination. Maybe it's possible to only get the selectedvalues in the response (have checked the props of the listbox)&lt;/P&gt;</description>
      <pubDate>Mon, 08 Feb 2021 08:14:15 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Integration-Extension-APIs/Export-data-from-bookmark-using-NodeJS-script/m-p/1780746#M13802</guid>
      <dc:creator>han</dc:creator>
      <dc:date>2021-02-08T08:14:15Z</dc:date>
    </item>
  </channel>
</rss>

