<?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: Issue with IIF statement in arcade for valueExpression in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/issue-with-iif-statement-in-arcade-for/m-p/1021806#M71549</link>
    <description>&lt;P&gt;Thanks &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/191789"&gt;@BlakeTerhune&lt;/a&gt;,. I initially tried to avoid arcade and use the first method that you mentioned, but I didn't know how to pass variables from code to expression like this:&amp;nbsp;&lt;/P&gt;&lt;P&gt;${treatmentPlan.pavementCondition}&lt;BR /&gt;I will try using this method. Thanks a lot!&lt;/P&gt;</description>
    <pubDate>Fri, 29 Jan 2021 23:15:52 GMT</pubDate>
    <dc:creator>RabinSubedi</dc:creator>
    <dc:date>2021-01-29T23:15:52Z</dc:date>
    <item>
      <title>Issue with IIF statement in arcade for valueExpression</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/issue-with-iif-statement-in-arcade-for/m-p/1021754#M71544</link>
      <description>&lt;P&gt;Hello Everyone,&lt;/P&gt;&lt;P&gt;I have two arrays pavementID and pavementCondition inside treatmentPlan object. I need to check if pavementID containes the Pavement ID of a layer (field: PvtID) or not. If yes, I have to use value of pavementCondition that corresponds with the index of PvtID in pavementID. If not, I have to use existing value of the layer (field: PCR_NBR). I wrote an arcade expression like this, but it didn't worked:&lt;/P&gt;&lt;P&gt;Can anyone help me with this?&lt;/P&gt;&lt;P&gt;Thank You.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;var arcadeExp = "IIF(" + treatmentPlan.pavementIDs.includes(+"$feature.PvtID" + ) + "," + treatmentPlan.pavementCondition[treatmentPlan.pavementIDs.indexOf(+"$feature.PvtID" + )] + ",$feature.PCR_NBR )";
                  var majorRoadRenderer = {
                    type: "class-breaks",
                    valueExpression: "(" + arcadeExp + ")",
                    classBreakInfos: [{
                        minValue: 86, 
                        maxValue: 100, 
                        symbol: {
                          color: "#005ce6",
                          type: "simple-line",
                          style: "solid",
                          width: "3px",
                        },
                      }, {
                        minValue: 76,
                        maxValue: 85, 
                        symbol: {
                          color: "#38a800",
                          type: "simple-line",
                          style: "solid",
                          width: "3px",
                        },
                      },
                      {
                        minValue: 66, 
                        maxValue: 75, 
                        symbol: {
                          color: "#fc921f",
                          type: "simple-line",
                          style: "solid",
                          width: "3px",
                        },
                      }, {
                        minValue: 56, 
                        maxValue: 65, 
                        symbol: {
                          color: "#e60000",
                          type: "simple-line",
                          style: "solid",
                          width: "3px",
                        },
                      }, {
                        minValue: 0, 
                        maxValue: 55, 
                        symbol: {
                          color: "#1a1a1a",
                          type: "simple-line",
                          style: "solid",
                          width: "3px",
                        },
                      }
                    ]
                  };&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Jan 2021 21:19:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/issue-with-iif-statement-in-arcade-for/m-p/1021754#M71544</guid>
      <dc:creator>RabinSubedi</dc:creator>
      <dc:date>2021-01-29T21:19:35Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with IIF statement in arcade for valueExpression</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/issue-with-iif-statement-in-arcade-for/m-p/1021765#M71546</link>
      <description>&lt;P&gt;Just a suggestion, but from most python stuff I've come across, you really just need to pass the expression in as string.&lt;/P&gt;&lt;P&gt;Perhaps:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;var arcadeExp = "IIF(treatmentPlan.pavementIDs.includes($feature.PvtID), treatmentPlan.pavementCondition[treatmentPlan.pavementIDs.indexOf($feature.PvtID)], $feature.PCR_NBR)"&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 29 Jan 2021 21:37:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/issue-with-iif-statement-in-arcade-for/m-p/1021765#M71546</guid>
      <dc:creator>DavidPike</dc:creator>
      <dc:date>2021-01-29T21:37:47Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with IIF statement in arcade for valueExpression</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/issue-with-iif-statement-in-arcade-for/m-p/1021798#M71548</link>
      <description>&lt;P&gt;You're mixing a lot of stuff up in that one assignment for&amp;nbsp;arcadeExp. There are syntax issues the way you have it now. Try splitting it up like this to simplify the logic. If this app is meant for modern browsers (ES6) use &lt;A href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals" target="_self"&gt;template literals&lt;/A&gt; to make it more readable.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var arcadeExp = `var indexPvtID = ${treatmentPlan.pavementIDs}.indexOf($feature.PvtID);
    IIF(
        indexPvtID &amp;gt;= 0,
        ${treatmentPlan.pavementCondition}[indexPvtID],
        $feature.PCR_NBR
    )`;&lt;/LI-CODE&gt;&lt;P&gt;It seems like there's a potential weak point with grabbing the value of&amp;nbsp;pavementCondition based on index from&amp;nbsp;pavementIDs. You'd be better off making&amp;nbsp;pavementCondition an object where the keys are the values from&amp;nbsp;pavementIDs and the value of each is whatever each value is in&amp;nbsp;pavementCondition.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;pavementCondition = {
  pavementID1: pavementConditionValue1,
  pavementID2: pavementConditionValue2,
  pavementID3: pavementConditionValue3,
  pavementID4: pavementConditionValue4,
  pavementID5: pavementConditionValue5,
  // etc...
}&lt;/LI-CODE&gt;&lt;P&gt;Then you could&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var arcadeExp = `var pavementCondition = ${treatmentPlan.pavementCondition};
    IIF(
        HasKey(pavementCondition, $feature.PvtID),
        pavementCondition[$feature.PvtID],
        $feature.PCR_NBR
    )`;&lt;/LI-CODE&gt;&lt;P&gt;I'm not an Arcade expert and haven't tested this so I might be missing something obvious but hopefully you can make it work.&lt;/P&gt;</description>
      <pubDate>Fri, 29 Jan 2021 22:47:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/issue-with-iif-statement-in-arcade-for/m-p/1021798#M71548</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2021-01-29T22:47:25Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with IIF statement in arcade for valueExpression</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/issue-with-iif-statement-in-arcade-for/m-p/1021806#M71549</link>
      <description>&lt;P&gt;Thanks &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/191789"&gt;@BlakeTerhune&lt;/a&gt;,. I initially tried to avoid arcade and use the first method that you mentioned, but I didn't know how to pass variables from code to expression like this:&amp;nbsp;&lt;/P&gt;&lt;P&gt;${treatmentPlan.pavementCondition}&lt;BR /&gt;I will try using this method. Thanks a lot!&lt;/P&gt;</description>
      <pubDate>Fri, 29 Jan 2021 23:15:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/issue-with-iif-statement-in-arcade-for/m-p/1021806#M71549</guid>
      <dc:creator>RabinSubedi</dc:creator>
      <dc:date>2021-01-29T23:15:52Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with IIF statement in arcade for valueExpression</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/issue-with-iif-statement-in-arcade-for/m-p/1022203#M71574</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/191789"&gt;@BlakeTerhune&lt;/a&gt;&amp;nbsp; I tried this method, but it doesn't allow me to pass array or object as a whole into the arcade expression, although I can pass a single value. I tried using JSON.stringify, it passes the entire content inside but it doesn't returns the value for given index (for eg. pvtID=100 here). I tried using JSON.parse inside the template literal to revert it back to object, but it throws same error as before.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var pvtInPlan = treatmentPlan.pavementIDs;
                  var pcrAfterPlan = treatmentPlan.pavementCondition;
                  var yearlyPlan = {};
                  pvtInPlan.forEach((key, i) =&amp;gt; yearlyPlan[key] = pcrAfterPlan[i]);
var arcadeExp = `
									var plan = ${JSON.stringify(yearlyPlan)};
									var planObj = JSON.parse(plan);
									var pvtID = 100;
									return planObj[pvtID]`;  //I am trying to pass a single value instead of IIF statement just to test if object is working or not&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Feb 2021 17:56:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/issue-with-iif-statement-in-arcade-for/m-p/1022203#M71574</guid>
      <dc:creator>RabinSubedi</dc:creator>
      <dc:date>2021-02-01T17:56:28Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with IIF statement in arcade for valueExpression</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/issue-with-iif-statement-in-arcade-for/m-p/1022209#M71575</link>
      <description>&lt;P&gt;Does it work without any of the JSON manipulation? I think Arcade should be able to use the JavaScript object natively.&lt;/P&gt;</description>
      <pubDate>Mon, 01 Feb 2021 18:11:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/issue-with-iif-statement-in-arcade-for/m-p/1022209#M71575</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2021-02-01T18:11:33Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with IIF statement in arcade for valueExpression</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/issue-with-iif-statement-in-arcade-for/m-p/1022213#M71576</link>
      <description>&lt;P&gt;No it doesn't. For example, if I use the following expression, it gives me an error:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;var arcadeExp = `
									var plan = ${yearlyPlan};
									var pvtID = 100;
									return plan[pvtID]`;&lt;/LI-CODE&gt;&lt;P&gt;But if I pass just one value, it works:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;var arcadeExp = `
									var plan = ${yearlyPlan[100]};
									return plan`;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is the error I get while passing object/array:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;a class='gotoLine' href='#"[esri.views.2d.layers.FeatureLayerView2D]", [object Object'&amp;gt;"[esri.views.2d.layers.FeatureLayerView2D]", [object Object&amp;lt;/a&amp;gt; {
  constructor: function e(b,g,d){var c=a.call(this,b,g,d)||this;return c instanceof
e?c:new e(b,g,d)},
  details: &amp;lt;a class='gotoLine' href='#object Object'&amp;gt;object Object&amp;lt;/a&amp;gt; {
    stack: "ra@https://js.arcgis.com/4.17/esri/support/arcadeUtils.js:403:347
sa@https://js.arcgis.com/4.17/esri/support/arcadeUtils.js:405:349
Q@https://js.arcgis.com/4.17/esri/support/arcadeUtils.js:405:421
M@https://js.arcgis.com/4.17/esri/support/arcadeUtils.js:406:41
E@https://js.arcgis.com/4.17/esri/support/arcadeUtils.js:409:336
X@https://js.arcgis.com/4.17/esri/support/arcadeUtils.js:407:181
db@https://js.arcgis.com/4.17/esri/support/arcadeUtils.js:416:267
X@https://js.arcgis.com/4.17/esri/support/arcadeUtils.js:407:181
Ha@https://js.arcgis.com/4.17/esri/support/arcadeUtils.js:417:470
X@https://js.arcgis.com/4.17/esri/support/arcadeUtils.js:407:181
Xa@https://js.arcgis.com/4.17/esri/support/arcadeUtils.js:419:9
Ga@https://js.arcgis.com/4.17/esri/support/arcadeUtils.js:420:156
X@https://js.arcgis.com/4.17/esri/support/arcadeUtils.js:407:181
eb@https://js.arcgis.com/4.17/esri/support/arcadeUtils.js:421:200
X@https://js.arcgis.com/4.17/esri/support/arcadeUtils.js:407:181
oa@https://js.arcgis.com/4.17/esri/support/arcadeUtils.js:423:69
da@https://js.arcgis.com/4.17/esri/support/arcadeUtils.js:407:84
Za@https://js.arcgis.com/4.17/esri/support/arcadeUtils.js:426:362
$a@https://js.arcgis.com/4.17/esri/support/arcadeUtils.js:426:497
Ca@https://js.arcgis.com/4.17/esri/support/arcadeUtils.js:432:230
Ra@https://js.arcgis.com/4.17/esri/support/arcadeUtils.js:426:157
ab@https://js.arcgis.com/4.17/esri/support/arcadeUtils.js:433:447
cb@https://js.arcgis.com/4.17/esri/support/arcadeUtils.js:436:265
Ra@https://js.arcgis.com/4.17/esri/support/arcadeUtils.js:426:140
esri/arcade/lib/esprima/&amp;amp;lt;/v.parse@https://js.arcgis.com/4.17/esri/support/arcadeUtils.js:462:35
esri/arcade/parser/&amp;amp;lt;/a.parseScript@https://js.arcgis.com/4.17/esri/support/arcadeUtils.js:381:192
y@https://js.arcgis.com/4.17/esri/support/arcadeUtils.js:4:499
esri/support/arcadeOnDemand/&amp;amp;lt;/f&amp;amp;lt;/a.create/&amp;amp;lt;/&amp;amp;lt;@https://js.arcgis.com/4.17/esri/views/2d/layers/features/Pipeline.js:590:85
d@https://js.arcgis.com/4.17/dojo/dojo-lite.js:47:190
c/&amp;amp;lt;@https://js.arcgis.com/4.17/dojo/dojo-lite.js:45:492
g@https://js.arcgis.com/4.17/dojo/dojo-lite.js:45:275
"
  },
  message: "Line 2: Unexpected identifier",
  name: "Error",
  toJSON: function(){if(null!=this.details)try{return{name:this.name,message:this.message,details:JSON.parse(JSON.stringify(this.details,function(a,b){if(b&amp;amp;&amp;amp;"object"===typeof b&amp;amp;&amp;amp;"function"===typeof b.toJSON)return b;try{return l.clone(b)}catch(d){return"&amp;lt;a class='gotoLine' href='#object'&amp;gt;object&amp;lt;/a&amp;gt;"}}))}}catch(n){throw h.getLogger("esri.core.Error").error(n),n;}return{name:this.name,message:this.message,details:this.details}},
  toString: function(){return"&amp;lt;a class='gotoLine' href='#"+this.name+"'&amp;gt;"+this.name+"&amp;lt;/a&amp;gt;: "+this.message},
  type: "error"
}]&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 01 Feb 2021 18:18:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/issue-with-iif-statement-in-arcade-for/m-p/1022213#M71576</guid>
      <dc:creator>RabinSubedi</dc:creator>
      <dc:date>2021-02-01T18:18:01Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with IIF statement in arcade for valueExpression</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/issue-with-iif-statement-in-arcade-for/m-p/1022282#M71578</link>
      <description>&lt;P&gt;I don't think JSON.parse() is available in Arcade so your assignment for planObj isn't needed. And just for testing to simplify everything, use the original JS object. What happens if you change it to&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var arcadeExp = `
    var planObj = ${JSON.stringify(treatmentPlan.pavementIDs)};
    var pvtID = 100;
    return planObj[pvtID]`;
console.log(arcadeExp);&lt;/LI-CODE&gt;&lt;P&gt;Then add a&amp;nbsp;&lt;FONT face="courier new,courier"&gt;console.log(arcadeExp)&lt;/FONT&gt; to make sure the Arcade expression is correct after JS inserts everything. You can verify the logged expression in the &lt;A href="https://developers.arcgis.com/arcade/playground/" target="_self"&gt;Arcade Playground&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Mon, 01 Feb 2021 20:39:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/issue-with-iif-statement-in-arcade-for/m-p/1022282#M71578</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2021-02-01T20:39:26Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with IIF statement in arcade for valueExpression</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/issue-with-iif-statement-in-arcade-for/m-p/1022324#M71579</link>
      <description>&lt;P&gt;That worked! I used the following code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;var arcadeExp = `
									var planID = ${JSON.stringify(treatmentPlan.pavementIDs)};
									var planPCR = ${JSON.stringify(treatmentPlan.pavementCondition)};
									var index = IndexOf(planID, $feature.PvtID);
									return IIF(index&amp;gt;=0, planPCR[index],$feature.PCR_NBR)`;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I noticed that, if we try to pass object or dictionary, it won't work. Also if we try to create dictionary inside arcade using arrays from stringify, it gives the same error.&lt;/P&gt;&lt;P&gt;Thank you very much for your help &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/191789"&gt;@BlakeTerhune&lt;/a&gt;. You are awesome!&lt;/P&gt;</description>
      <pubDate>Mon, 01 Feb 2021 21:37:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/issue-with-iif-statement-in-arcade-for/m-p/1022324#M71579</guid>
      <dc:creator>RabinSubedi</dc:creator>
      <dc:date>2021-02-01T21:37:57Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with IIF statement in arcade for valueExpression</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/issue-with-iif-statement-in-arcade-for/m-p/1022327#M71580</link>
      <description>&lt;P&gt;Glad you found a solution and appreciate you posting it. I didn't realize that putting an object in the JS template literal that it comes out as&amp;nbsp;&lt;FONT face="courier new,courier"&gt;[object Object]&lt;/FONT&gt; so that JSON.stringify() was a great find on your part!&lt;/P&gt;</description>
      <pubDate>Mon, 01 Feb 2021 21:55:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/issue-with-iif-statement-in-arcade-for/m-p/1022327#M71580</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2021-02-01T21:55:00Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with IIF statement in arcade for valueExpression</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/issue-with-iif-statement-in-arcade-for/m-p/1022332#M71581</link>
      <description>&lt;P&gt;It was all because of your effort &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/191789"&gt;@BlakeTerhune&lt;/a&gt; . Thanks Much!&lt;/P&gt;&lt;P&gt;It is interesting that the result of JSON.stringify(array) behaves as a text in normal JS and as an array in arcade while indexing.&lt;/P&gt;</description>
      <pubDate>Mon, 01 Feb 2021 22:03:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/issue-with-iif-statement-in-arcade-for/m-p/1022332#M71581</guid>
      <dc:creator>RabinSubedi</dc:creator>
      <dc:date>2021-02-01T22:03:33Z</dc:date>
    </item>
  </channel>
</rss>

