<?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: Arcade - 'System.InvalidCastException' in Attribute Rules Questions</title>
    <link>https://community.esri.com/t5/attribute-rules-questions/arcade-system-invalidcastexception/m-p/1207107#M547</link>
    <description>&lt;P&gt;The Arcade expression returns a Dictionary, but it seems like JS can't convert that.&lt;/P&gt;&lt;P&gt;Sadly, I have no idea about the JS API. You can probably get some help in the&amp;nbsp;&lt;A href="https://community.esri.com/t5/arcgis-api-for-javascript/ct-p/arcgis-api-for-javascript" target="_blank"&gt;ArcGIS API for JavaScript - Esri Community&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 29 Aug 2022 08:09:57 GMT</pubDate>
    <dc:creator>JohannesLindner</dc:creator>
    <dc:date>2022-08-29T08:09:57Z</dc:date>
    <item>
      <title>Arcade - 'System.InvalidCastException'</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/arcade-system-invalidcastexception/m-p/1205314#M524</link>
      <description>&lt;P&gt;Hello! I have an expression "var d = Dictionary('Accounting', $feature.AssessmentID)\r\nreturn d" and if the value is null, I get an exception:&lt;BR /&gt;Values = '((Esri.ArcGISRuntime.RuntimeDictionary&amp;lt;string, object&amp;gt;)result.Result).Values' threw an exception of type 'System.InvalidCastException'&lt;/P&gt;&lt;P&gt;I researched that I could write like this "$feature.AssessmentID +'' " and no exception. Any other options?&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Tue, 23 Aug 2022 10:41:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/arcade-system-invalidcastexception/m-p/1205314#M524</guid>
      <dc:creator>girafee</dc:creator>
      <dc:date>2022-08-23T10:41:36Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade - 'System.InvalidCastException'</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/arcade-system-invalidcastexception/m-p/1205324#M525</link>
      <description>&lt;P&gt;Hey!&lt;/P&gt;&lt;P&gt;This expression returns a dictionary. Are you sure you need a dictionary and not a string or something else?&lt;/P&gt;&lt;P&gt;What do you want to do with this expression? Is it for an Attribute Rule?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Aug 2022 11:25:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/arcade-system-invalidcastexception/m-p/1205324#M525</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2022-08-23T11:25:22Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade - 'System.InvalidCastException'</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/arcade-system-invalidcastexception/m-p/1205938#M537</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/294341"&gt;@JohannesLindner&lt;/a&gt;I'm sure. I need to return the dictionary and work with it.&lt;BR /&gt;What options do we have?&lt;/P&gt;</description>
      <pubDate>Wed, 24 Aug 2022 16:46:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/arcade-system-invalidcastexception/m-p/1205938#M537</guid>
      <dc:creator>girafee</dc:creator>
      <dc:date>2022-08-24T16:46:59Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade - 'System.InvalidCastException'</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/arcade-system-invalidcastexception/m-p/1206219#M538</link>
      <description>&lt;P&gt;You could return a json string representation of the dictionary:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var d = Dictionary('Accounting', $feature.AssessmentID)
return Text(d)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But the problem isn't with the expression. You want to use the output dictionary somewhere and that is what's causing the error.&lt;/P&gt;&lt;P&gt;Can you tell us what you're trying to do? If we know what you're working with and what you want to accomplish, it's much easier to help.&lt;/P&gt;</description>
      <pubDate>Thu, 25 Aug 2022 06:34:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/arcade-system-invalidcastexception/m-p/1206219#M538</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2022-08-25T06:34:55Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade - 'System.InvalidCastException'</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/arcade-system-invalidcastexception/m-p/1206664#M546</link>
      <description>&lt;LI-CODE lang="csharp"&gt;public override async Task ExecuteAsync(Feature feature)
{

Esri.ArcGISRuntime.ArcadeExpression ArcadeEvaluatorExpression = new Esri.ArcGISRuntime.ArcadeExpression("var d = Dictionary('Accounting1', $feature.AssessmentID)\r\nreturn d"); // AssessmentID = null

ArcadeEvaluator ArcadeEvaluator = new ArcadeEvaluator(ArcadeEvaluatorExpression, ArcadeProfile.FormCalculation);

List&amp;lt;KeyValuePair&amp;lt;string, object&amp;gt;&amp;gt; profileVariables = new List&amp;lt;KeyValuePair&amp;lt;string, object&amp;gt;&amp;gt;();

profileVariables.Add(new KeyValuePair&amp;lt;string, object&amp;gt;("$feature", feature));

ArcadeEvaluationResult result = await ArcadeEvaluator.EvaluateAsync(profileVariables);

Dictionary&amp;lt;string, object&amp;gt; retValues = JObject.FromObject(result.Result).ToObject&amp;lt;Dictionary&amp;lt;string, object&amp;gt;&amp;gt;();

if (retValues != null)
{
   foreach (KeyValuePair&amp;lt;string, object&amp;gt; pair in retValues)
   feature.SetAttributeValue(pair.Key, pair.Value);
}

}&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 26 Aug 2022 08:33:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/arcade-system-invalidcastexception/m-p/1206664#M546</guid>
      <dc:creator>girafee</dc:creator>
      <dc:date>2022-08-26T08:33:02Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade - 'System.InvalidCastException'</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/arcade-system-invalidcastexception/m-p/1207107#M547</link>
      <description>&lt;P&gt;The Arcade expression returns a Dictionary, but it seems like JS can't convert that.&lt;/P&gt;&lt;P&gt;Sadly, I have no idea about the JS API. You can probably get some help in the&amp;nbsp;&lt;A href="https://community.esri.com/t5/arcgis-api-for-javascript/ct-p/arcgis-api-for-javascript" target="_blank"&gt;ArcGIS API for JavaScript - Esri Community&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 29 Aug 2022 08:09:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/arcade-system-invalidcastexception/m-p/1207107#M547</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2022-08-29T08:09:57Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade - 'System.InvalidCastException'</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/arcade-system-invalidcastexception/m-p/1209684#M566</link>
      <description>&lt;P&gt;I want to have a null check in my expression and if it is null, return null as a string: &lt;SPAN&gt;"var d = Dictionary('Accounting', $feature.AssessmentID)\r\nreturn d". For example: "if($feature.AssessmentID == null) $feature.AssesmentID = 'null'".&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Sep 2022 15:04:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/arcade-system-invalidcastexception/m-p/1209684#M566</guid>
      <dc:creator>girafee</dc:creator>
      <dc:date>2022-09-05T15:04:33Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade - 'System.InvalidCastException'</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/arcade-system-invalidcastexception/m-p/1209692#M567</link>
      <description>&lt;P&gt;Like this?&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;if($feature.AssessmentID == null) {
    return "null"
}
return {"Accounting": $feature.AssessmentID}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Or do you want to set the value in the table to "null"?&lt;/P&gt;</description>
      <pubDate>Mon, 05 Sep 2022 15:16:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/arcade-system-invalidcastexception/m-p/1209692#M567</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2022-09-05T15:16:47Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade - 'System.InvalidCastException'</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/arcade-system-invalidcastexception/m-p/1216591#M583</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="e9ad3c23-a791-42dd-9869-8ace0060e68f.png" style="width: 697px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/52310iB1DAF1F30B6508C5/image-dimensions/697x108?v=v2" width="697" height="108" role="button" title="e9ad3c23-a791-42dd-9869-8ace0060e68f.png" alt="e9ad3c23-a791-42dd-9869-8ace0060e68f.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Hi! Could you please help me? I have the same problem and I don't know how to solve it. I need to return dictionary from Arcade Expression, and work with it. But if at least one value is null, I get an exception and can't work with other values.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;public override async Task ExecuteAsync(Feature feature)
{
Esri.ArcGISRuntime.ArcadeExpression ArcadeEvaluatorExpression = new Esri.ArcGISRuntime.ArcadeExpression("var d = Dictionary() \r\n if($feature.AuthorizationNotice == null) \r\n { d['QuantityActual'] = $feature.Status \r\n d['Assessor'] = $feature.DueDate \r\n return d}"); // $feature.DueDate = null

ArcadeEvaluator ArcadeEvaluator = new ArcadeEvaluator(ArcadeEvaluatorExpression, ArcadeProfile.FormCalculation);

List&amp;lt;KeyValuePair&amp;lt;string, object&amp;gt;&amp;gt; profileVariables = new List&amp;lt;KeyValuePair&amp;lt;string, object&amp;gt;&amp;gt;();

profileVariables.Add(new KeyValuePair&amp;lt;string, object&amp;gt;("$feature", feature));

ArcadeEvaluationResult result = await ArcadeEvaluator.EvaluateAsync(profileVariables); // here we have System.InvalidCastException

Dictionary&amp;lt;string, object&amp;gt; retValues = JObject.FromObject(result.Result).ToObject&amp;lt;Dictionary&amp;lt;string, object&amp;gt;&amp;gt;();

if (retValues != null)
{
   foreach (KeyValuePair&amp;lt;string, object&amp;gt; pair in retValues)
   feature.SetAttributeValue(pair.Key, pair.Value);
}

}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Sep 2022 16:47:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/arcade-system-invalidcastexception/m-p/1216591#M583</guid>
      <dc:creator>girafee</dc:creator>
      <dc:date>2022-09-27T16:47:53Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade - 'System.InvalidCastException'</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/arcade-system-invalidcastexception/m-p/1216659#M584</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;P&gt;&lt;SPAN&gt;I have the same problem&lt;/SPAN&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;SPAN&gt;In fact, it's exactly the same problem, this is your thread...&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Sadly, I'm as unqualified as before. I don't know anything about JS. I guess you couldn't find help in the JS Community?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I am qualified to look at your Arcade expression (it's different from the one you posted earlier), and I'm not sure what you're trying to achieve.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var d = Dictionary() 
if($feature.AuthorizationNotice == null) {
    d['QuantityActual'] = $feature.Status
    d['Assessor'] = $feature.DueDate
    return d
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Here's what your expression does:&lt;/SPAN&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;SPAN&gt;if AuthorizationNotice is null, return a dictionary&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN&gt;if AuthorizationNotice is not null, return null&lt;/SPAN&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;SPAN&gt;Is this the intended behavior?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Sep 2022 18:29:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/arcade-system-invalidcastexception/m-p/1216659#M584</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2022-09-27T18:29:46Z</dc:date>
    </item>
  </channel>
</rss>

