Select to view content in your preferred language

Arcade Assign Attributes in List Individual Colors based on IIF

572
13
Jump to solution
11-05-2024 01:20 PM
Ed_
by MVP Regular Contributor
MVP Regular Contributor

So i have three attributes in the list, "severity", "probability" and date. I would like to show severity in red when its value is "Severe" and probability red as well when its value is "Likely". Second, i wouldn't like the date to have any color change. 

I know i have to use HTML source formatting in conjunction with Arcade for this purpose. How can I do this?

Bonus question: How can i please add a calendar icon next to the date? Please note that the date is in the second line

Current output:

Ed__0-1730841601856.png

 



Thank you 🙂

 

Current Arcade:

/ Condition Color the Attributes
var colorS = IIF($datapoint.severity == "Severe", "#ff0000", '')
var colorP = IIF($datapoint.probability == "Likely", "#ff0000", '')


return {
  textColor: colorS,
  backgroundColor: '',
  separatorColor:'',
  selectionColor: '',
  selectionTextColor: '',
  // attributes: {
    // attribute1: '',
    // attribute2: ''
  // }
}

 

Current HTML source:


<p>
    <strong>{field/severity}, {field/probability}</strong><br>
    {field/date_and_time}
</p>

 

Question | Analyze | Visualize
0 Kudos
2 Solutions

Accepted Solutions
JenniferAcunto
Esri Regular Contributor

Just add your fields to the line template w/o the arcade fields. Then use the rich text editor to add generic color to your fonts, then open the source field and swap out the hex code for your arcade attribute in the HTML.

JenniferAcunto_0-1730917572406.png

 

- Jen

View solution in original post

JenniferAcunto
Esri Regular Contributor

Just add the emoji in the line item template next to your field: {field/date_and_time} :alarm_clock:

JenniferAcunto_0-1730921115306.png

 

- Jen

View solution in original post

13 Replies
Ed_
by MVP Regular Contributor
MVP Regular Contributor

@KenBuja another question for you sir!

Question | Analyze | Visualize
0 Kudos
JenniferAcunto
Esri Regular Contributor

You will want to return all three arcade variables as attributes, and then plug those attributes directly into the HTML of the Line Item Template. Scroll down to the Arcade Attributes section of this blog post for a step by step explanation. 

As far as a clock icon, the easiest thing would be to use a clock emoji :alarm_clock:. Emojis are great because they are essentially just text and you can add them just like you would any other text in the list. Otherwise, you would need to use an SVG code and some HTML. 


Icon Repositories:

Iconmonstr 

Iconoir 

Phosphor

Emojipedia (Emojis)

- Jen
Ed_
by MVP Regular Contributor
MVP Regular Contributor

Good morning Jennifer, hope all is well and thank you for the quick response so I try doing what you did in the blog, but as you can see i am still not there. Can you please help further with this?

Also, how and where exactly should i put the emoji text in the Arcade expression and HTML?

Arcade expression:

/ Condition Color the Attributes
var colorS = IIF($datapoint.how_severe_could_the_injury_to == "Severe", "#ff0000", '')
var colorP = IIF($datapoint.what_is_the_probability_that_in == "Likely", "#ff0000", '')


return {
  textColor: colorS,
  backgroundColor: '',
  separatorColor:'',
  selectionColor: '',
  selectionTextColor: '',
  attributes: {
    attribute1: '',
    attribute2: ''
  // }
}
}

 

HTML code:

<p>
    <strong>{field/how_severe_could_the_injury_to}, {field/what_is_the_probability_that_in}</strong><br>
    {field/date_and_time}
</p>
<p>
    &nbsp;
</p>
<p>
    <span style="color:{expression/attribute1};"><i><span style="box-sizing:border-box;"></span></i></span><span style="background-color:rgb(255,255,255);color:#ff0000;font-size:16px;"><span style="box-sizing:border-box;font-family:&quot;Avenir Next W01&quot;, &quot;Avenir Next W00&quot;, &quot;Avenir Next&quot;, Avenir, &quot;Helvetica Neue&quot;, sans-serif;font-style:normal;font-variant-caps:normal;font-variant-ligatures:normal;font-weight:300;letter-spacing:normal;orphans:2;text-align:left;text-decoration-color:initial;text-decoration-style:initial;text-indent:0px;text-transform:none;white-space:normal;widows:2;word-spacing:0px;">&nbsp;</span></span>
</p>
Question | Analyze | Visualize
0 Kudos
Ed_
by MVP Regular Contributor
MVP Regular Contributor

@JenniferAcunto I also tried the following but it's still the same

 

<p><span style="color:{expression/attribute1}"> </span> {how_severe_could_the_injury_to}</p>
<p><span style="color:{expression/attribute2}"> </span> {what_is_the_probability_that_in}</p>

 

Current output:

Ed__0-1730915054088.png

 

 

Question | Analyze | Visualize
0 Kudos
JenniferAcunto
Esri Regular Contributor

You need to tell the return statement what each of those attributes are.

return {
textColor: colorS,
backgroundColor: '',
separatorColor:'',
selectionColor: '',
selectionTextColor: '',
attributes: {
attribute1: colorS,
attribute2: colorP
// }
}
}

- Jen
Ed_
by MVP Regular Contributor
MVP Regular Contributor

Hi Jennifer, thank you so I did that but now the output is showing the hexcode in red

// Condition Color the Attributes
var colorS = IIF($datapoint.how_severe_could_the_injury_to == "Severe", "#ff0000", '')
var colorP = IIF($datapoint.what_is_the_probability_that_in == "Likely", "#ff0000", '')


return {
  textColor: colorS,
  backgroundColor: '',
  separatorColor:'',
  selectionColor: '',
  selectionTextColor: '',
  attributes: {
    attribute1: colorS,
    attribute2: colorP
  // }
}
}

 

HTML:

<p>
    <strong>{field/how_severe_could_the_injury_to}, {field/what_is_the_probability_that_in}</strong><br>
    {field/date_and_time}
</p>
<p>
    &nbsp;

<p><span style="color:{expression/attribute1}"> </span> {how_severe_could_the_injury_to}</p>
<p><span style="color:{expression/attribute2}"> </span> {what_is_the_probability_that_in}</p>

 

Current output:

Ed__0-1730915457245.png

 

Question | Analyze | Visualize
0 Kudos
JenniferAcunto
Esri Regular Contributor
<p>
    <span style="color:{expression/attribute1};">{how_severe_could_the_injury_to}</span>, <span style="color:{exoressuib.attribute2};">{what_is_the_probability_that_in}</span>
</p>
- Jen
0 Kudos
Ed_
by MVP Regular Contributor
MVP Regular Contributor

Hi Jen, thank you for the quick response but it's still not working

<p>
    <span style="color:{expression/attribute1};"><strong>{how_severe_could_the_injury_to}</strong></span>, <span style="color:{expression/attribute2};"><strong>{what_is_the_probability_that_in}</strong></span>
</p>

 

Ed__0-1730916610924.png

 

Question | Analyze | Visualize
0 Kudos
JenniferAcunto
Esri Regular Contributor

Just add your fields to the line template w/o the arcade fields. Then use the rich text editor to add generic color to your fonts, then open the source field and swap out the hex code for your arcade attribute in the HTML.

JenniferAcunto_0-1730917572406.png

 

- Jen