<?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: Set Property of a Class with Return Value From async Request in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/set-property-of-a-class-with-return-value-from/m-p/22282#M1939</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In case anyone&amp;nbsp;needs this, here's how I got it to work:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;DIV style="color: #d4d4d4; background-color: #1e1e1e; font-weight: normal; font-size: 14px;"&gt;&lt;DIV&gt;&lt;SPAN style="color: #d4d4d4;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color: #569cd6;"&gt;private&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color: #569cd6;"&gt;async&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color: #dcdcaa;"&gt;_getLayerGroups&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;()&amp;nbsp;{&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN style="color: #d4d4d4;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color: #569cd6;"&gt;let&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color: #9cdcfe;"&gt;layerGroups&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;&amp;nbsp;=&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color: #c586c0;"&gt;await&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color: #dcdcaa;"&gt;request&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #ce9178;"&gt;"https://gis.server.com/arcgis/rest/"&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;,&amp;nbsp;{&lt;/SPAN&gt;&lt;SPAN style="color: #9cdcfe;"&gt;query:&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;&amp;nbsp;{&lt;/SPAN&gt;&lt;SPAN style="color: #9cdcfe;"&gt;f:&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color: #ce9178;"&gt;"json"&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;},&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color: #9cdcfe;"&gt;responseType:&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color: #ce9178;"&gt;"json"&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;}).&lt;/SPAN&gt;&lt;SPAN style="color: #dcdcaa;"&gt;then&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #9cdcfe;"&gt;response&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color: #569cd6;"&gt;=&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color: #9cdcfe;"&gt;response&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;.&lt;/SPAN&gt;&lt;SPAN style="color: #9cdcfe;"&gt;data&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;.&lt;/SPAN&gt;&lt;SPAN style="color: #9cdcfe;"&gt;folders&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;);&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You need to nest the request call in an async function and use await to make sure the value is available. This code returns an array, so I had to change the property type accordingly also.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 24 Jul 2020 14:26:43 GMT</pubDate>
    <dc:creator>BenRomlein</dc:creator>
    <dc:date>2020-07-24T14:26:43Z</dc:date>
    <item>
      <title>Set Property of a Class with Return Value From async Request</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/set-property-of-a-class-with-return-value-from/m-p/22279#M1936</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Using JS API 4.14, I have a custom Accessor class serving as the view model to a UI widget. I want to query a server to get a list of service&amp;nbsp;groups available, and render that list in the UI. I have a property in my class that I want to set to the return value of the request:&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;DIV style="color: #d4d4d4; background-color: #1e1e1e; font-weight: normal; font-size: 14px;"&gt;&lt;DIV&gt;&lt;SPAN style="color: #d4d4d4;"&gt;&amp;nbsp;&amp;nbsp;@&lt;/SPAN&gt;&lt;SPAN style="color: #dcdcaa;"&gt;property&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;()&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN style="color: #d4d4d4;"&gt;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color: #9cdcfe;"&gt;layerGroups&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;:&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color: #4ec9b0;"&gt;string&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;&amp;nbsp;=&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color: #569cd6;"&gt;null&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;I'm trying to use the code below to make the request and set the value, but this does not work.&amp;nbsp;No console error, but the value of layerGroups&amp;nbsp;remains null. I assume because request is an async operation, so it doesn't have access to the return value at the right time.&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;&amp;gt; widget.viewModel.layerGroups&lt;BR /&gt;&amp;gt; null&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;DIV style="color: #d4d4d4; background-color: #1e1e1e; font-weight: normal; font-size: 14px;"&gt;&lt;DIV&gt;&lt;SPAN style="color: #d4d4d4;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color: #569cd6;"&gt;const&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color: #9cdcfe;"&gt;getLayerGroups&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;&amp;nbsp;=&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color: #dcdcaa;"&gt;request&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #ce9178;"&gt;"https://my.server/arcgis/rest/"&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;,&amp;nbsp;{&lt;/SPAN&gt;&lt;SPAN style="color: #9cdcfe;"&gt;query:&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;&amp;nbsp;{&lt;/SPAN&gt;&lt;SPAN style="color: #9cdcfe;"&gt;f:&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color: #ce9178;"&gt;"json"&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;},&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color: #9cdcfe;"&gt;responseType:&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color: #ce9178;"&gt;"json"&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;}).&lt;/SPAN&gt;&lt;SPAN style="color: #dcdcaa;"&gt;then&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #9cdcfe;"&gt;response&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color: #569cd6;"&gt;=&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color: #569cd6;"&gt;this&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;.&lt;/SPAN&gt;&lt;SPAN style="color: #dcdcaa;"&gt;set&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #569cd6;"&gt;this&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;.&lt;/SPAN&gt;&lt;SPAN style="color: #9cdcfe;"&gt;layerGroups&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;,&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color: #9cdcfe;"&gt;response&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;.&lt;/SPAN&gt;&lt;SPAN style="color: #9cdcfe;"&gt;data&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;.&lt;/SPAN&gt;&lt;SPAN style="color: #9cdcfe;"&gt;folders&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;));&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Normally, I'd just nest the rest of my code in the callback and I'd have easy access to the returned value. But the Accessor class/widget code is more compartmentalized, and I'm not sure how and where to implement things.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How can I make this work? Do I need to put my async operations in a different lifecycle section of my class (I've only tried them in the constructor)? Is this a scoping issue? Appreciate any advice you have. Thanks!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;EDIT: request here is the esri/request:&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;DIV style="color: #d4d4d4; background-color: #1e1e1e; font-weight: normal; font-size: 14px;"&gt;&lt;DIV&gt;&lt;SPAN style="color: #c586c0;"&gt;import&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color: #9cdcfe;"&gt;request&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;&amp;nbsp;=&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color: #c586c0;"&gt;require&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #ce9178;"&gt;"esri/request"&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;);&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/BLOCKQUOTE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Mar 2020 15:19:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/set-property-of-a-class-with-return-value-from/m-p/22279#M1936</guid>
      <dc:creator>BenRomlein</dc:creator>
      <dc:date>2020-03-11T15:19:24Z</dc:date>
    </item>
    <item>
      <title>Re: Set Property of a Class with Return Value From async Request</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/set-property-of-a-class-with-return-value-from/m-p/22280#M1937</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;bump...&lt;/P&gt;&lt;P&gt;Still looking for advice on this is anyone has employed a similar work-flow.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 23 Mar 2020 12:34:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/set-property-of-a-class-with-return-value-from/m-p/22280#M1937</guid>
      <dc:creator>BenRomlein</dc:creator>
      <dc:date>2020-03-23T12:34:13Z</dc:date>
    </item>
    <item>
      <title>Re: Set Property of a Class with Return Value From async Request</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/set-property-of-a-class-with-return-value-from/m-p/22281#M1938</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;bump.&lt;BR /&gt;Anyone have anything on this?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 08 Apr 2020 14:27:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/set-property-of-a-class-with-return-value-from/m-p/22281#M1938</guid>
      <dc:creator>BenRomlein</dc:creator>
      <dc:date>2020-04-08T14:27:49Z</dc:date>
    </item>
    <item>
      <title>Re: Set Property of a Class with Return Value From async Request</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/set-property-of-a-class-with-return-value-from/m-p/22282#M1939</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In case anyone&amp;nbsp;needs this, here's how I got it to work:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;DIV style="color: #d4d4d4; background-color: #1e1e1e; font-weight: normal; font-size: 14px;"&gt;&lt;DIV&gt;&lt;SPAN style="color: #d4d4d4;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color: #569cd6;"&gt;private&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color: #569cd6;"&gt;async&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color: #dcdcaa;"&gt;_getLayerGroups&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;()&amp;nbsp;{&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN style="color: #d4d4d4;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color: #569cd6;"&gt;let&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color: #9cdcfe;"&gt;layerGroups&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;&amp;nbsp;=&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color: #c586c0;"&gt;await&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color: #dcdcaa;"&gt;request&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #ce9178;"&gt;"https://gis.server.com/arcgis/rest/"&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;,&amp;nbsp;{&lt;/SPAN&gt;&lt;SPAN style="color: #9cdcfe;"&gt;query:&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;&amp;nbsp;{&lt;/SPAN&gt;&lt;SPAN style="color: #9cdcfe;"&gt;f:&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color: #ce9178;"&gt;"json"&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;},&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color: #9cdcfe;"&gt;responseType:&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color: #ce9178;"&gt;"json"&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;}).&lt;/SPAN&gt;&lt;SPAN style="color: #dcdcaa;"&gt;then&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #9cdcfe;"&gt;response&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color: #569cd6;"&gt;=&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color: #9cdcfe;"&gt;response&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;.&lt;/SPAN&gt;&lt;SPAN style="color: #9cdcfe;"&gt;data&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;.&lt;/SPAN&gt;&lt;SPAN style="color: #9cdcfe;"&gt;folders&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;);&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You need to nest the request call in an async function and use await to make sure the value is available. This code returns an array, so I had to change the property type accordingly also.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 24 Jul 2020 14:26:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/set-property-of-a-class-with-return-value-from/m-p/22282#M1939</guid>
      <dc:creator>BenRomlein</dc:creator>
      <dc:date>2020-07-24T14:26:43Z</dc:date>
    </item>
  </channel>
</rss>

