<?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: Value from a promise object? in Integration, Extension &amp; APIs</title>
    <link>https://community.qlik.com/t5/Integration-Extension-APIs/Value-from-a-promise-object/m-p/1621760#M11257</link>
    <description>&lt;P&gt;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/9886"&gt;@oz_moyal&lt;/a&gt;&amp;nbsp;I gave that a try earlier and just redid it now with the added console.log. It isn't even showing up and the extension container is empty. I figure its something stupid like a missed parenthesis or something but the error catching isn't great in qlik. Side note - I really appreciate you trying to help me with this.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;define(['jquery', 'qlik', 'css!./Dane-Selections_Applier.css', './properties', 'ng!$q'], function ($, qlik, cssContent, properties, $q) {
    return {
        definition: properties,
        paint: function ($element, layout, jquery,properties) {
            app = qlik.currApp();			
			const getFieldList = function () {
				var defer = $q.defer();
				app.getList( 'FieldList', function (items) {
					defer.resolve( items.qFieldList.qItems.map( function (item) {
						return {
							value: item.qName,
							label: item.qName
						}
					}));
				});
				return defer.promise;
			};		
			
			getFieldList().then(function (result) {
				//here the promise had already resolved
				
					var dropdownHTMLCode = '&amp;lt;select&amp;gt;';
					result.layout.qFieldList.qItems.forEach(function (row) {
						dropdownHTMLCode += ('&amp;lt;option value="' + row.qName+ '"&amp;gt;' + row.qName + '&amp;lt;/option&amp;gt;');
					});
					dropdownHTMLCode += '&amp;lt;/select&amp;gt;';
					
					var buttonHTMLCode = '&amp;lt;button name="ApplySelections" id="applySelections-'+layout.qInfo.qId+'" class="applySelections"&amp;gt;Apply Selections'+((layout.field=='')?'':' to '+ layout.field)+'&amp;lt;/button&amp;gt;';
            		var textboxHTMLCode = '&amp;lt;textarea id="selectionsTextboxArea-'+layout.qInfo.qId+'" style="height: 10%;width: 90%;font-size: 10px;" placeholder="test"&amp;gt;&amp;lt;/textarea&amp;gt;';
            		$element.html(dropdownHTMLCode + '&amp;lt;table style="height:10%;text-align: center;"&amp;gt;&amp;lt;tr&amp;gt;&amp;lt;td style="width:20%;"&amp;gt;'+buttonHTMLCode+'&amp;lt;/td&amp;gt;&amp;lt;td style="width:80%;"&amp;gt;'+textboxHTMLCode+'&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&amp;lt;/table&amp;gt;');
            		addOnActivateButtonEvent($element,layout,app);
					console.log(dropdownHTMLCode);
					console.log('test');
				});				
        }
    };
}); &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 09 Sep 2019 20:44:43 GMT</pubDate>
    <dc:creator>danelooman</dc:creator>
    <dc:date>2019-09-09T20:44:43Z</dc:date>
    <item>
      <title>Value from a promise object?</title>
      <link>https://community.qlik.com/t5/Integration-Extension-APIs/Value-from-a-promise-object/m-p/1621243#M11245</link>
      <description>&lt;P&gt;I have the following code which returns a promise object. In inspector it goes from $$state 0 to $$state 1 and then shows the values of the filters I am trying to return to a variable. Anytime I try to return that value it doesn't work because its a promise that I assume has not been resolved yet. What can I do to get that value and wrap my head around the promise structure. (Apologies if this is a stupid question).&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const getFieldList = function () {
				var defer = $q.defer();
				app.getList( 'FieldList', function (items) {
					defer.resolve( items.qFieldList.qItems.map( function (item) {
						return {
							value: item.qName,
							label: item.qName
						}
					}));
				});
				return defer.promise;
			};
			
			let test = function () {
                            return getFieldList().then(function (items) {
                                return items;
                            });
                        };
			console.log(test().$$state.value);&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 06 Sep 2019 19:13:52 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Integration-Extension-APIs/Value-from-a-promise-object/m-p/1621243#M11245</guid>
      <dc:creator>danelooman</dc:creator>
      <dc:date>2019-09-06T19:13:52Z</dc:date>
    </item>
    <item>
      <title>Re: Value from a promise object?</title>
      <link>https://community.qlik.com/t5/Integration-Extension-APIs/Value-from-a-promise-object/m-p/1621660#M11250</link>
      <description>&lt;P&gt;when u use console.log, it does not wait for the promise to resolve&lt;BR /&gt;&lt;BR /&gt;how about using this approach:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const getFieldList = function () {
 return(app.getList('FieldList'))
}

getFieldList.then(function(result) {
  console.log(result);
  //or do any prcoessing to the result
});&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;or if u want&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const getFieldList = function () {
 return new Promise(function(resolve, reject) {
     app.getList('FieldList').then (function(result) {

var items= //process the items from the result

resolve(items);

}

});

getFieldList.then(function(items) {
  console.log(items);
  });&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Sep 2019 14:43:36 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Integration-Extension-APIs/Value-from-a-promise-object/m-p/1621660#M11250</guid>
      <dc:creator>oz_moyal</dc:creator>
      <dc:date>2019-09-09T14:43:36Z</dc:date>
    </item>
    <item>
      <title>Re: Value from a promise object?</title>
      <link>https://community.qlik.com/t5/Integration-Extension-APIs/Value-from-a-promise-object/m-p/1621681#M11252</link>
      <description>&lt;P&gt;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/9886"&gt;@oz_moyal&lt;/a&gt;&amp;nbsp;&amp;nbsp;That makes a lot of sense. I want to add the results into a drop down with code like by assigning the results to a variable(in this case test)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;dropdownHTMLCode = '&amp;lt;select&amp;gt;' + test.foreach((e){ return '&amp;lt;option value=' + e.value + '&amp;gt;' + e.label + '&amp;lt;/option&amp;gt;'; }) +	'&amp;lt;/select&amp;gt;';		&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The problem is when this runs I don't think the promise has completed assigning the values to test so the drop down is empty.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Sep 2019 16:36:12 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Integration-Extension-APIs/Value-from-a-promise-object/m-p/1621681#M11252</guid>
      <dc:creator>danelooman</dc:creator>
      <dc:date>2019-09-09T16:36:12Z</dc:date>
    </item>
    <item>
      <title>Re: Value from a promise object?</title>
      <link>https://community.qlik.com/t5/Integration-Extension-APIs/Value-from-a-promise-object/m-p/1621730#M11253</link>
      <description>&lt;P&gt;In that case, it can be even simpler:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;app.getList('FieldList').then(function (result) {
//here the promise had already resolved
    dropdownHTMLCode = '&amp;lt;select&amp;gt;';
    result.layout.qFieldList.qItems.forEach(function (row) {
        dropdownHTMLCode += '&amp;lt;option value=' + row.qName+ '&amp;gt;' + row.qName + '&amp;lt;/option&amp;gt;';
    });
    dropdownHTMLCode = '&amp;lt;/select&amp;gt;';
    console.log(dropdownHTMLCode );
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;or if u want function to return this string:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;function getHTMLcode() {
return new Promise(function(resolve, reject) {
    app.getList('FieldList').then(function (result) {
        //here the promise had already resolved
        dropdownHTMLCode = '&amp;lt;select&amp;gt;';
        result.layout.qFieldList.qItems.forEach(function (row) {
            dropdownHTMLCode += '&amp;lt;option value=' + row.qName+ '&amp;gt;' + row.qName + '&amp;lt;/option&amp;gt;';
            });
        dropdownHTMLCode = '&amp;lt;/select&amp;gt;';
        resolve(dropdownHTMLCode);
        });
    });
}
getHTMLcode().then(function (dropdownHTMLCode) {console.log(dropdownHTMLCode);});&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Sep 2019 19:33:01 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Integration-Extension-APIs/Value-from-a-promise-object/m-p/1621730#M11253</guid>
      <dc:creator>oz_moyal</dc:creator>
      <dc:date>2019-09-09T19:33:01Z</dc:date>
    </item>
    <item>
      <title>Re: Value from a promise object?</title>
      <link>https://community.qlik.com/t5/Integration-Extension-APIs/Value-from-a-promise-object/m-p/1621735#M11255</link>
      <description>&lt;P&gt;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/9886"&gt;@oz_moyal&lt;/a&gt;&amp;nbsp; I must be missing something. I tried to render the drop down and all I get is undefined or if I move everything into the promise I get nothing returned. Its like the page is rendering faster than the promise.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;define(['jquery', 'qlik', 'css!./Dane-Selections_Applier.css', './properties', 'ng!$q'], function ($, qlik, cssContent, properties, $q) {
    return {
        definition: properties,
        paint: function ($element, layout, jquery,properties) {
            app = qlik.currApp();			
			const getFieldList = function () {
				var defer = $q.defer();
				app.getList( 'FieldList', function (items) {
					defer.resolve( items.qFieldList.qItems.map( function (item) {
						return {
							value: item.qName,
							label: item.qName
						}
					}));
				});
				return defer.promise;
			};		
			
			var dropdownHTMLCode;
			getFieldList().then(function (result) {
				//here the promise had already resolved
					dropdownHTMLCode = '&amp;lt;select&amp;gt;';
					result.layout.qFieldList.qItems.forEach(function (row) {
						dropdownHTMLCode += '&amp;lt;option value=' + row.qName+ '&amp;gt;' + row.qName + '&amp;lt;/option&amp;gt;';
					});
					dropdownHTMLCode += '&amp;lt;/select&amp;gt;';	
				});	
								
			var buttonHTMLCode = '&amp;lt;button name="ApplySelections" id="applySelections-'+layout.qInfo.qId+'" class="applySelections"&amp;gt;Apply Selections'+((layout.field=='')?'':' to '+ layout.field)+'&amp;lt;/button&amp;gt;';
            var textboxHTMLCode = '&amp;lt;textarea id="selectionsTextboxArea-'+layout.qInfo.qId+'" style="height: 10%;width: 90%;font-size: 10px;" placeholder="test"&amp;gt;&amp;lt;/textarea&amp;gt;';
            $element.html(dropdownHTMLCode + '&amp;lt;table style="height:10%;text-align: center;"&amp;gt;&amp;lt;tr&amp;gt;&amp;lt;td style="width:20%;"&amp;gt;'+buttonHTMLCode+'&amp;lt;/td&amp;gt;&amp;lt;td style="width:80%;"&amp;gt;'+textboxHTMLCode+'&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&amp;lt;/table&amp;gt;');
            addOnActivateButtonEvent($element,layout,app);
        }
    };
}); 

//Helper funciton for adding on a "qv-activate" event of button/link
var addOnActivateButtonEvent = function ($element,layout,app) {
    $("#applySelections-"+layout.qInfo.qId).on('qv-activate', function () {
        console.log(0);
        var selectionsInput = document.getElementById("selectionsTextboxArea-"+layout.qInfo.qId).value.split('\n');
        selectionsInput = selectionsInput.filter(function(n){ return n != "" });
        selections = layout.isNumeric ? selectionsInput.map(function(item){return parseFloat(item);}) : selectionsInput;
        console.log('Selections to be applied are:', selections);
        app.field(layout.field).selectValues(selections, true,true);
    });
};&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 09 Sep 2019 19:52:07 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Integration-Extension-APIs/Value-from-a-promise-object/m-p/1621735#M11255</guid>
      <dc:creator>danelooman</dc:creator>
      <dc:date>2019-09-09T19:52:07Z</dc:date>
    </item>
    <item>
      <title>Re: Value from a promise object?</title>
      <link>https://community.qlik.com/t5/Integration-Extension-APIs/Value-from-a-promise-object/m-p/1621736#M11256</link>
      <description>&lt;P&gt;u can't use&amp;nbsp;dropdownHTMLCode&amp;nbsp;&lt;/P&gt;&lt;P&gt;out of the promise , it will not have the value there&lt;BR /&gt;&lt;BR /&gt;u need to move all this lines:&lt;/P&gt;&lt;PRE&gt;var buttonHTMLCode = '&amp;lt;button name="ApplySelections" id="applySelections-'+layout.qInfo.qId+'" class="applySelections"&amp;gt;Apply Selections'+((layout.field=='')?'':' to '+ layout.field)+'&amp;lt;/button&amp;gt;';
            var textboxHTMLCode = '&amp;lt;textarea id="selectionsTextboxArea-'+layout.qInfo.qId+'" style="height: 10%;width: 90%;font-size: 10px;" placeholder="test"&amp;gt;&amp;lt;/textarea&amp;gt;';
            $element.html(dropdownHTMLCode + '&amp;lt;table style="height:10%;text-align: center;"&amp;gt;&amp;lt;tr&amp;gt;&amp;lt;td style="width:20%;"&amp;gt;'+buttonHTMLCode+'&amp;lt;/td&amp;gt;&amp;lt;td style="width:80%;"&amp;gt;'+textboxHTMLCode+'&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&amp;lt;/table&amp;gt;');
            addOnActivateButtonEvent($element,layout,app);&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;after this line:&lt;/P&gt;&lt;PRE&gt;dropdownHTMLCode += '&amp;lt;/select&amp;gt;';	&lt;/PRE&gt;&lt;P&gt;so it is inside the "then" function block.&lt;BR /&gt;please also add after this line:&lt;BR /&gt;console.log(dropdownHTMLCode);&amp;nbsp; so u can test its content in the console.&lt;/P&gt;</description>
      <pubDate>Mon, 09 Sep 2019 20:00:58 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Integration-Extension-APIs/Value-from-a-promise-object/m-p/1621736#M11256</guid>
      <dc:creator>oz_moyal</dc:creator>
      <dc:date>2019-09-09T20:00:58Z</dc:date>
    </item>
    <item>
      <title>Re: Value from a promise object?</title>
      <link>https://community.qlik.com/t5/Integration-Extension-APIs/Value-from-a-promise-object/m-p/1621760#M11257</link>
      <description>&lt;P&gt;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/9886"&gt;@oz_moyal&lt;/a&gt;&amp;nbsp;I gave that a try earlier and just redid it now with the added console.log. It isn't even showing up and the extension container is empty. I figure its something stupid like a missed parenthesis or something but the error catching isn't great in qlik. Side note - I really appreciate you trying to help me with this.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;define(['jquery', 'qlik', 'css!./Dane-Selections_Applier.css', './properties', 'ng!$q'], function ($, qlik, cssContent, properties, $q) {
    return {
        definition: properties,
        paint: function ($element, layout, jquery,properties) {
            app = qlik.currApp();			
			const getFieldList = function () {
				var defer = $q.defer();
				app.getList( 'FieldList', function (items) {
					defer.resolve( items.qFieldList.qItems.map( function (item) {
						return {
							value: item.qName,
							label: item.qName
						}
					}));
				});
				return defer.promise;
			};		
			
			getFieldList().then(function (result) {
				//here the promise had already resolved
				
					var dropdownHTMLCode = '&amp;lt;select&amp;gt;';
					result.layout.qFieldList.qItems.forEach(function (row) {
						dropdownHTMLCode += ('&amp;lt;option value="' + row.qName+ '"&amp;gt;' + row.qName + '&amp;lt;/option&amp;gt;');
					});
					dropdownHTMLCode += '&amp;lt;/select&amp;gt;';
					
					var buttonHTMLCode = '&amp;lt;button name="ApplySelections" id="applySelections-'+layout.qInfo.qId+'" class="applySelections"&amp;gt;Apply Selections'+((layout.field=='')?'':' to '+ layout.field)+'&amp;lt;/button&amp;gt;';
            		var textboxHTMLCode = '&amp;lt;textarea id="selectionsTextboxArea-'+layout.qInfo.qId+'" style="height: 10%;width: 90%;font-size: 10px;" placeholder="test"&amp;gt;&amp;lt;/textarea&amp;gt;';
            		$element.html(dropdownHTMLCode + '&amp;lt;table style="height:10%;text-align: center;"&amp;gt;&amp;lt;tr&amp;gt;&amp;lt;td style="width:20%;"&amp;gt;'+buttonHTMLCode+'&amp;lt;/td&amp;gt;&amp;lt;td style="width:80%;"&amp;gt;'+textboxHTMLCode+'&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&amp;lt;/table&amp;gt;');
            		addOnActivateButtonEvent($element,layout,app);
					console.log(dropdownHTMLCode);
					console.log('test');
				});				
        }
    };
}); &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Sep 2019 20:44:43 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Integration-Extension-APIs/Value-from-a-promise-object/m-p/1621760#M11257</guid>
      <dc:creator>danelooman</dc:creator>
      <dc:date>2019-09-09T20:44:43Z</dc:date>
    </item>
    <item>
      <title>Re: Value from a promise object?</title>
      <link>https://community.qlik.com/t5/Integration-Extension-APIs/Value-from-a-promise-object/m-p/1621764#M11258</link>
      <description>&lt;P&gt;It seem to me the issue is with&lt;BR /&gt;const getFieldList = function () {&lt;BR /&gt;&lt;BR /&gt;I do not know if return the promise and the values properly, i wrote it differently, in what i sent u.&lt;BR /&gt;&lt;BR /&gt;can u try to put this code in the beginning paint function, and check the console log:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;app.getList('FieldList').then(function (result) {
//here the promise had already resolved
    dropdownHTMLCode = '&amp;lt;select&amp;gt;';
    result.layout.qFieldList.qItems.forEach(function (row) {
        dropdownHTMLCode += '&amp;lt;option value=' + row.qName+ '&amp;gt;' + row.qName + '&amp;lt;/option&amp;gt;';
    });
    dropdownHTMLCode += '&amp;lt;/select&amp;gt;';
    console.log(dropdownHTMLCode );
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Sep 2019 20:53:59 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Integration-Extension-APIs/Value-from-a-promise-object/m-p/1621764#M11258</guid>
      <dc:creator>oz_moyal</dc:creator>
      <dc:date>2019-09-09T20:53:59Z</dc:date>
    </item>
    <item>
      <title>Re: Value from a promise object?</title>
      <link>https://community.qlik.com/t5/Integration-Extension-APIs/Value-from-a-promise-object/m-p/1622180#M11266</link>
      <description>&lt;P&gt;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/9886"&gt;@oz_moyal&lt;/a&gt;&amp;nbsp;&amp;nbsp;just wanted to let you know that worked like a charm. Thank you so much.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Sep 2019 14:27:51 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Integration-Extension-APIs/Value-from-a-promise-object/m-p/1622180#M11266</guid>
      <dc:creator>danelooman</dc:creator>
      <dc:date>2019-09-10T14:27:51Z</dc:date>
    </item>
  </channel>
</rss>

