<?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: How to store arcade expression as variable for use in another expression in ArcGIS Online Questions</title>
    <link>https://community.esri.com/t5/arcgis-online-questions/how-to-store-arcade-expression-as-variable-for-use/m-p/1093490#M41928</link>
    <description>&lt;P&gt;You just have to order your code differently:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var Status = $feature.RefStatus

// exit early if RefStatus is null
if(IsEmpty(Status)) {
  return ''
}

var cover_status = [
  'Ants present under artificial cover object',
  'Artificial cover object not found',
  'Artificial cover object not checked'
]
var water_status = [
  'Current',
  'Empty',
  'Inaccessible',
  'Polluted'
  'Filled'
]
if(Includes(cover_status, Status)) {
  return 'Artificial cover object status: ' + Status
}
if(Includes(water_status, Status)) {
  return 'Waterbody status: ' + Status
}
return ''

// for older Arcade versions (&amp;lt; Arcade 1.12):
var status_type = ''
if (Status=='Ants present under artificial cover object' || Status=='Artificial cover object not found' || Status=='Artificial cover object not checked') {
  return 'Artificial cover object status: ' + Status
}
if (Status=='Current' || Status=='Empty' || Status=='Inaccessible' || Status=='Polluted' || Status=='Filled') {
  return 'Waterbody status: ' + Status
}
return ''&lt;/LI-CODE&gt;</description>
    <pubDate>Mon, 30 Aug 2021 08:07:53 GMT</pubDate>
    <dc:creator>JohannesLindner</dc:creator>
    <dc:date>2021-08-30T08:07:53Z</dc:date>
    <item>
      <title>How to store arcade expression as variable for use in another expression</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/how-to-store-arcade-expression-as-variable-for-use/m-p/1093049#M41914</link>
      <description>&lt;P&gt;I am using Arcade to customise my popups in ArcGIS Online. I have a scenario where I am wanting to run one Arcade expression to return a value, and then use that value in another expression. However it is not quite working out and I am probably missing something obvious. Here is my expression:&lt;/P&gt;&lt;P&gt;&lt;EM&gt;var Status = $feature.RefStatus&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;var label = $feature.RefStatus; if (Status =='Ants present under artificial cover object'){&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;return 'Artificial cover object status: ';&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;} else if (Status=='Artificial cover object not found') {&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;return 'Artificial cover object status: ';&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;} else if (Status=='Artificial cover object not checked'){&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;return 'Artificial cover object status: ';&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;} else if (Status=='Current'){&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;return 'Waterbody status: ';&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;} else if (Status=='Empty'){&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;return 'Waterbody status: ';&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;} else if (Status=='Inaccessible'){&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;return 'Waterbody status: ';&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;} else if (Status=='Polluted'){&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;return 'Waterbody status: ';&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;} else if (Status=='Filled'){&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;return 'Waterbody status: ';&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;} else {&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;return '';&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;}&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;IIF(isEmpty($feature.RefStatus), "", label)&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;I want the first expression to store either the value 'Artificial cover object status: ' or 'Waterbody status: ' based on the contents of the RefStatus field, and the second expression to return the output of the first expression if the field is not empty.&lt;BR /&gt;&lt;BR /&gt;Is there a way of storing an expression as a variable for use in a subsequent expression?&lt;BR /&gt;&lt;BR /&gt;I have tried creating the expression separately and then referencing that expression in the 2nd one (e.g.&amp;nbsp;&amp;nbsp;&lt;EM&gt;IIF(isEmpty($feature.RefStatus), "", {expression/expr6})&lt;/EM&gt; but this throws an error. I have also tried assigning the first expression to a variable (e.g. &lt;EM&gt;var label&amp;nbsp; = if (Status&lt;/EM&gt;....) but this also does not work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;BR /&gt;Rob&lt;/P&gt;</description>
      <pubDate>Fri, 27 Aug 2021 09:30:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/how-to-store-arcade-expression-as-variable-for-use/m-p/1093049#M41914</guid>
      <dc:creator>DataOfficer</dc:creator>
      <dc:date>2021-08-27T09:30:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to store arcade expression as variable for use in another expression</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/how-to-store-arcade-expression-as-variable-for-use/m-p/1093059#M41916</link>
      <description>&lt;P&gt;I do not think that this is possible simply because arcade expressions, when used for popups, only work for the particular layer that it corresponds to. You could try setting up the arcade expression &lt;A href="https://www.esri.com/arcgis-blog/products/arcgis-online/data-management/pump-up-your-pop-ups-with-arcade-and-the-living-atlas/" target="_blank" rel="noopener"&gt;to work with other features/geometries to see when one feature changes, then the arcade expression in the other feature also changes&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;This is my best guess for when it comes to creating custom popups using arcade expressions. Perhaps someone else in the community or Esri can give you further insight.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 27 Aug 2021 11:48:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/how-to-store-arcade-expression-as-variable-for-use/m-p/1093059#M41916</guid>
      <dc:creator>RPGIS</dc:creator>
      <dc:date>2021-08-27T11:48:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to store arcade expression as variable for use in another expression</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/how-to-store-arcade-expression-as-variable-for-use/m-p/1093112#M41918</link>
      <description>&lt;P&gt;Sorry I should have been clearer. The expressions are pulling information from the same layer.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 27 Aug 2021 14:24:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/how-to-store-arcade-expression-as-variable-for-use/m-p/1093112#M41918</guid>
      <dc:creator>DataOfficer</dc:creator>
      <dc:date>2021-08-27T14:24:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to store arcade expression as variable for use in another expression</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/how-to-store-arcade-expression-as-variable-for-use/m-p/1093490#M41928</link>
      <description>&lt;P&gt;You just have to order your code differently:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var Status = $feature.RefStatus

// exit early if RefStatus is null
if(IsEmpty(Status)) {
  return ''
}

var cover_status = [
  'Ants present under artificial cover object',
  'Artificial cover object not found',
  'Artificial cover object not checked'
]
var water_status = [
  'Current',
  'Empty',
  'Inaccessible',
  'Polluted'
  'Filled'
]
if(Includes(cover_status, Status)) {
  return 'Artificial cover object status: ' + Status
}
if(Includes(water_status, Status)) {
  return 'Waterbody status: ' + Status
}
return ''

// for older Arcade versions (&amp;lt; Arcade 1.12):
var status_type = ''
if (Status=='Ants present under artificial cover object' || Status=='Artificial cover object not found' || Status=='Artificial cover object not checked') {
  return 'Artificial cover object status: ' + Status
}
if (Status=='Current' || Status=='Empty' || Status=='Inaccessible' || Status=='Polluted' || Status=='Filled') {
  return 'Waterbody status: ' + Status
}
return ''&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 30 Aug 2021 08:07:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/how-to-store-arcade-expression-as-variable-for-use/m-p/1093490#M41928</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2021-08-30T08:07:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to store arcade expression as variable for use in another expression</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/how-to-store-arcade-expression-as-variable-for-use/m-p/1094842#M41977</link>
      <description>&lt;P&gt;Amazing, thank you so much for this. This is much more elegant as well.&lt;BR /&gt;It wasn't returning the&amp;nbsp;&lt;STRONG&gt;Artificial cover object status:&lt;/STRONG&gt; text but it turned out that this was due to the fact that 3 of the status' were listed as domains.&amp;nbsp;&lt;BR /&gt;Changing the first line to&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;var Status = DomainName($feature,"RefStatus")&lt;/LI-CODE&gt;&lt;P&gt;resolved the issue.&lt;/P&gt;&lt;P&gt;Also just had to fix a missing comma on line 17 after 'Polluted'.&lt;/P&gt;</description>
      <pubDate>Thu, 02 Sep 2021 10:10:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/how-to-store-arcade-expression-as-variable-for-use/m-p/1094842#M41977</guid>
      <dc:creator>DataOfficer</dc:creator>
      <dc:date>2021-09-02T10:10:12Z</dc:date>
    </item>
  </channel>
</rss>

