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!
Solved! Go to Solution.
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}`
);
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}`
);
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:
This is going to save me a lot of time writing definition queries and making custom popups for things!
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.
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!
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
}