Select to view content in your preferred language

Attribute expression - show/hide fields if value is NULL

1849
9
Jump to solution
08-12-2024 02:51 AM
petera
by
Emerging Contributor

Hi everyone - 

This will probably be very straightforward for the right person but my working knowledge of Arcade and attribute expressions is next to nothing: I was ecstatic when I managed to write an expression to convert m2 to ha and round it to 2 decimal places but I need some assistance with something a little more complicated ...

I have two fields in layer - {status} and {expected_delivery}.  Where {status} is "Delivered since 2018" there is nothing in {expected_delivery} but where {status} is "Active", "Pipeline" or "Opportunity" there may be additional information in {expected_delivery} ... but not always!

What I want to do is write an expression that will show {status} if {expected_delivery} is blank; and {status} & " ," & {expected_delivery} if {expected_delivery} is not blank.

I found some information on If expressions that looked like it might do the trick but I couldn't get it to output what I was after and it didn't take too long to realise I was out of my depth - any ideas?

Thanks!

0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

Here's an example how to do that using IIf, IsEmpty and template literals

return iif(
  IsEmpty($feature.expected_delivery),
  status,
  `${$feature.status}, ${$feature.expected_delivery}`
);

 

 

 

View solution in original post

9 Replies
KenBuja
MVP Esteemed Contributor

Here's an example how to do that using IIf, IsEmpty and template literals

return iif(
  IsEmpty($feature.expected_delivery),
  status,
  `${$feature.status}, ${$feature.expected_delivery}`
);

 

 

 

petera
by
Emerging Contributor

Thanks Ken, that worked perfectly!

return iif
( 
  IsEmpty($feature.Expected_Delivery), $feature.Status,
  `${$feature.Status}, ${$feature.Expected_Delivery}`
);


  The attribute expression gives the two different outputs I was after at the bottom of the popups:

Untitled-2.jpg

This is going to save me a lot of time writing definition queries and making custom popups for things!

0 Kudos
petera
by
Emerging Contributor

As a follow up, is it possible to include hyperlinks in this sort of thing?

There are a number of projects that have either case studies, websites or both associated with them.  At the moment, I have to make a layer filtered to show only those that have the case studies and/or website and write the following into the popups for them:

<p>
    Read the {Short_Title} <a href="{Case_Study}" target="_blank">Case Study</a>.
</p>

To make this sort of thing where "Railway and Bus Station Masterplan" is the {Short_Title} and URL for the hyperlink is the {Case_Study} field.

hyperlink.jpg

I altered the first expression to show nothing if the Case Study URL field is empty but to display the text part if there is a Case Study URL but I have no clue if it is possible to make the words "Case Study" into a clickable link with the field[Case_Study} as the destination.

return iif
( 
  IsEmpty($feature.Case_Study), " ",
  `Read the ${$feature.Short_Title} Case Study`
);

Is this even possible within the attribute expressions?

Thanks again for any ideas - really appreciate it!

0 Kudos
KenBuja
MVP Esteemed Contributor

You'll have to use an Arcade element, which can return html code.

var output = iif
( 
  IsEmpty($feature.Case_Study), " ",
  `Read the ${$feature.Short_Title} <a href="${feature.Case_Study}">Case Study</a>`
);

return { 
	type : 'text', 
	text : output 
}
0 Kudos
AndreaB_
Frequent Contributor

Hi! I'm trying to get this to work with my map and data. And it isn't working. It just doesn't show the link in the popup. Is this still valid code for today's ArcGIS Online arcade element?

Thank you,

A

0 Kudos
KenBuja
MVP Esteemed Contributor

The code still works when I test it in the Map Viewer. Can you post your code?

0 Kudos
AndreaB_
Frequent Contributor

Sure, thanks.

var output = iif
( 
  IsEmpty($feature.Link2), " ",
  `<a href="${feature.Link2}">Library Reference</a>`
);

return { 
	type : 'text', 
	text : output
}

 

0 Kudos
KenBuja
MVP Esteemed Contributor

Can you show what some of the values of Link2 are?

0 Kudos
AndreaB_
Frequent Contributor

The field was created in ArcGIS Online into the hosted feature layer and has a field display name on it of "Additional Link". I only have one value in that field right now:

AndreaB__0-1780083537966.png

The url value is: https://circusworld.catalogaccess.com/objects/284 

 

0 Kudos