Hello, I'm trying to write an expression that will return one of three image urls based on an inspection date. The distinction being the most recent date is less than 30 days, greater than 30 days, or there is no recent date. The expression is then pasted into the URL of an image for a pop up. Here is what I have so far.
<SPAN class="keyword token">var</SPAN> relatedrecords <SPAN class="operator token">=</SPAN> <SPAN class="token function">OrderBy</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="token function">FeatureSetByRelationshipName</SPAN><SPAN class="punctuation token">(</SPAN>$feature<SPAN class="punctuation token">,</SPAN><SPAN class="string token">"AST_Inspection"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"insp_date DESC"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">var</SPAN> cnt <SPAN class="operator token">=</SPAN> <SPAN class="token function">Count</SPAN><SPAN class="punctuation token">(</SPAN>relatedrecords<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">var</SPAN> relatedinfo <SPAN class="operator token">=</SPAN> <SPAN class="string token">""</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>cnt<SPAN class="operator token">></SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN>
<SPAN class="keyword token">var</SPAN> info <SPAN class="operator token">=</SPAN> <SPAN class="token function">First</SPAN><SPAN class="punctuation token">(</SPAN>relatedrecords<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
relateddate <SPAN class="operator token">=</SPAN> <SPAN class="token function">Text</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="token function">ToLocal</SPAN><SPAN class="punctuation token">(</SPAN>info<SPAN class="punctuation token">.</SPAN>insp_date<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"MM/DD/Y"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">var</SPAN> diff <SPAN class="operator token">=</SPAN> <SPAN class="token function">DateDiff</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="token function">Now</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> relateddate<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"days"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
relatedinfo <SPAN class="operator token">=</SPAN> IIf <SPAN class="punctuation token">(</SPAN>diff<SPAN class="operator token"><</SPAN><SPAN class="number token">30</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"img1url"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"img2url"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN> <SPAN class="keyword token">else</SPAN> <SPAN class="punctuation token">{</SPAN>
relatedinfo<SPAN class="operator token">=</SPAN> <SPAN class="string token">"img3url"</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="keyword token">return</SPAN> relatedinfo<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>I tried nesting If/Else statements and it just kept giving the Else image url. I'm sure there is a simpler way to do this, but I'm not sure.
Thanks.