<?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: API reading and applying selection issue and looping in Integration, Extension &amp; APIs</title>
    <link>https://community.qlik.com/t5/Integration-Extension-APIs/API-reading-and-applying-selection-issue-and-looping/m-p/1243748#M6670</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I assume that the reason for the looping is due to the onclick event of the underlying filter being triggered and not returning to my function.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 16 Mar 2017 13:58:36 GMT</pubDate>
    <dc:creator>rbartley</dc:creator>
    <dc:date>2017-03-16T13:58:36Z</dc:date>
    <item>
      <title>API reading and applying selection issue and looping</title>
      <link>https://community.qlik.com/t5/Integration-Extension-APIs/API-reading-and-applying-selection-issue-and-looping/m-p/1243747#M6669</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello all,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am having a couple of issues at the moment with using the APIs to read and make selections.&amp;nbsp; The scenario is as follows:&amp;nbsp; I have a&amp;nbsp; mashup featuring a number of dimensions and a chart.&amp;nbsp; Because some of the dimensions are mutually exclusive, I have created an unlinked dimension so that the values in the filter panel will not be affected by the selection of the other dimensions.&amp;nbsp; This works fine in that all the values I would expect to see in the filter list are displayed.&amp;nbsp; However, I then want to apply the values selected in the unlinked dimension filter to the dimension in the chart and this is where things go wring in that:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1) The code seems to keep looping even though I apply the filter outside of the $.each loop and use a "return true" to escape the loop.&lt;/P&gt;&lt;P&gt;2) The selection only works if I select one value or if I hard code the selections rather than using &lt;SPAN style="color: #3366ff; font-size: 13.3333px;"&gt;value.qSelected &lt;SPAN style="color: #000000;"&gt;(I tried formatting the string to be the same as the hard-coded values but it still doesn't seem to work, so I'm obviously doing something wrong). &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; This is what I am doing:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1) Set up mouseup&amp;nbsp; event on the div containing the filter Qlik filter panel (I have also tried with the click event) which calls function&lt;/P&gt;&lt;PRE __default_attr="javascript" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_148889952108488 jive_text_macro" jivemacro_uid="_148889952108488" modifiedtitle="true"&gt;
&lt;P&gt;$('#filterPigAndCereals').mouseup(function (obj){&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; var strCerealsFilter;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; strCerealsFilter = filterCerealCategory(qlik,app); &lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; });&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2) Create a function to read the selection object to find out which fields and values have been selected and if they refer to the field I am interested in then filter the dimension in the chart.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="javascript" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14888995651333967 jive_text_macro" jivemacro_uid="_14888995651333967" modifiedtitle="true"&gt;
&lt;P&gt;function filterCerealCategory(qlik,app)&lt;/P&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; var intSelectedCerealsValues=0;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; var objSelectionsList = app.getList("SelectionObject", function(reply){&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; $.each(reply.qSelectionObject.qSelections, function(key, value) {&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; var field = value.qField;&amp;nbsp; //The field name&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; var numSelected=0;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; intSelectedCerealsValues=0;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; if(field=="Cereals Category Price Unlinked")&lt;/P&gt;
&lt;P&gt;&amp;nbsp; {&lt;/P&gt;
&lt;P&gt;&amp;nbsp; numSelected= value.qSelectedCount;&amp;nbsp; //Number of selections in field&lt;/P&gt;
&lt;P&gt;&amp;nbsp; selections = value.qSelected;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; //console.log('selections=',selections);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; }&amp;nbsp; &lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; if(field=="Cereals Category Price Unlinked" &amp;amp;&amp;amp;&amp;nbsp; numSelected&amp;gt;0)&lt;/P&gt;
&lt;P&gt;&amp;nbsp; {&lt;/P&gt;
&lt;P&gt;&amp;nbsp; intSelectedCerealsValues++;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; return true;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; }&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; }); //end each qSelections&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; if(intSelectedCerealsValues &amp;gt; 0)&lt;/P&gt;
&lt;P&gt;&amp;nbsp; {&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; console.log('selections=',selections);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; app.field("Cereals Category (Price)").selectValues([selections]);&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; qlik.resize();&lt;/P&gt;
&lt;P&gt;&amp;nbsp; return true;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; }&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any help would be much appreciated.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Richard&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 Mar 2017 15:16:26 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Integration-Extension-APIs/API-reading-and-applying-selection-issue-and-looping/m-p/1243747#M6669</guid>
      <dc:creator>rbartley</dc:creator>
      <dc:date>2017-03-07T15:16:26Z</dc:date>
    </item>
    <item>
      <title>Re: API reading and applying selection issue and looping</title>
      <link>https://community.qlik.com/t5/Integration-Extension-APIs/API-reading-and-applying-selection-issue-and-looping/m-p/1243748#M6670</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I assume that the reason for the looping is due to the onclick event of the underlying filter being triggered and not returning to my function.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Mar 2017 13:58:36 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Integration-Extension-APIs/API-reading-and-applying-selection-issue-and-looping/m-p/1243748#M6670</guid>
      <dc:creator>rbartley</dc:creator>
      <dc:date>2017-03-16T13:58:36Z</dc:date>
    </item>
  </channel>
</rss>

