Select to view content in your preferred language

Getting Text formatting (Arcade & HTML) to work in Field Maps Popup

831
2
06-01-2023 12:09 AM
Labels (1)
LindsayRaabe_FPCWA
MVP Regular Contributor

I've written an arcade script which pulls dates from a table using a lookup for a selected feature in the map. The popup returns the results as a list of Fields, with some text green or red depending on if the data has "expired" (date in the past or future). 

You can see the text formatting on lines 28-32. What I want to know is do I need to change something or do it differently to get this working in Field Maps? Currently it works great in an Experience Builder WebApp, but not Field Maps (screenshots below). 

 

 

 

// Built from this reference page: https://learn.arcgis.com/en/projects/access-attributes-from-another-layer-with-arcade/
// Get OpCode from layer
var OpCode = $feature.Ops_Code

// Get required DAS attributes as a FeatureSet
var DASFSet = FeatureSetByName($map, "Disturbance Approvals Report",
['Plantation', 'DBCA_Tenure', 'DAS_Approval_Number', 'DAS_Approval_Date',	
'DAS_Expiry_Date', 'DAS_CM_Proposal_Doc_URI', 'DAS_CM_Approval_Doc_URI'], false)

// Filter DAS FeatureSet to only return values for the relevant OpCode
var filteredDASFSet = Filter(DASFSet, 'Ops_Code = @OpCode')
// Select the first OpCode in the FeatureSet
//   This essentially changes the data type from FeatureSet to a feature because in this case, there is only one feature in each FeatureSet
var filteredDAS = First(filteredDASFSet)

// Calculate values to return in output string
var URLStart = 'https://cm.fpc.wa.gov.au/HPEContentManager/HPRMServiceApi/Record/'
var URLFinish = '/File/Document'

var DBCA_Tenure =  IIf(filteredDAS.DBCA_Tenure == "Yes", "Yes - DAS Required", "No - DAS not required")
var DAS_Approval_Number = IIf(filteredDAS.DBCA_Tenure == "Yes", filteredDAS.DAS_Approval_Number,"")
var DAS_Approval_Date = IIf(filteredDAS.DBCA_Tenure == "Yes", Text(filteredDAS.DAS_Approval_Date, 'DD/MM/Y'),"")
var DAS_CM_Proposal_URL = IIf(filteredDAS.DBCA_Tenure == "Yes", IIf(isempty(filteredDAS.DAS_CM_Proposal_Doc_URI) == True, "", URLStart + filteredDAS.DAS_CM_Proposal_Doc_URI + URLFinish),"")
var DAS_CM_Approval_URL = IIf(filteredDAS.DBCA_Tenure == "Yes", IIf(isempty(filteredDAS.DAS_CM_Approval_Doc_URI) == True, "", URLStart + filteredDAS.DAS_CM_Approval_Doc_URI + URLFinish),"")

// Check Expiry date and format accordingly

var ExpiredFormat = [{"Status": Text(filteredDAS.DAS_Expiry_Date, 'DD/MM/Y') + " (Expired)","color":"red"}, {"Status":Text(filteredDAS.DAS_Expiry_Date, 'DD/MM/Y') + " (Current)","color":"green"},]

var findExpFormat = When(filteredDAS.DAS_Expiry_Date < Now(),ExpiredFormat[0],ExpiredFormat[1])

var DAS_Expiry_Date_Formatted = IIf(isempty(filteredDAS.DAS_Expiry_Date) == True, "", IIf(filteredDAS.DBCA_Tenure == "Yes", `<span style="color:${findExpFormat.color};">${findExpFormat.Status} </span>`,""))

// Output dictionary as fields to display in the pop-up

return {
    type: 'fields',
    title: 'DAS Details',
    //description : '',
    fieldInfos:  [{
          fieldName: "DBCA Tenure"  // fieldName should match the key in the attributes dictionary
        },
        {
          fieldName: "DAS Approval #"  // fieldName should match the key in the attributes dictionary
        },
        {
          fieldName: "DAS Approval Date"  // fieldName should match the key in the attributes dictionary
        },
        {
          fieldName: "DAS Expiry Date"  // fieldName should match the key in the attributes dictionary
        },
        {
          fieldName: "Proposal"  // fieldName should match the key in the attributes dictionary
        },
        {
          fieldName: "Approval"  // fieldName should match the key in the attributes dictionary
        }],
    attributes : {"DBCA Tenure" : DBCA_Tenure, "DAS Approval #" : DAS_Approval_Number, "DAS Approval Date" : DAS_Approval_Date, "DAS Expiry Date" : DAS_Expiry_Date_Formatted, "Proposal" : DAS_CM_Proposal_URL, "Approval" : DAS_CM_Approval_URL}  // replace this dictionary with your own key-value pairs
}

 

 

LindsayRaabe_FPCWA_2-1718687868383.png

LindsayRaabe_FPCWA_2-1685603278394.png

 

 

 

Lindsay Raabe
GIS Officer
Forest Products Commission WA
0 Kudos
2 Replies
LindsayRaabe_FPCWA
MVP Regular Contributor

Still no joy on this one. Anyone out there got any insights on how to format text strings in Field Maps AND WebApps?

Lindsay Raabe
GIS Officer
Forest Products Commission WA
0 Kudos
MitchellGrafstein
Frequent Contributor

Might have to return text instead?  Not sure how that looks in Experience Builder though. (Edit - Seems to work there, as well.)  Unfortunately, there are a lot of different contexts that show a lot of different things differently.  (Apologies for how vague that part is.)  I've found that you will see differences in pop-ups in Web Map Viewer, Field Maps, and elsewhere - and how you return or display those pop-ups will also yield differences.  (As in, you can add a text pop-up, and you add an expression to it you calculated, and that might show different results than adding an Arcade pop-up with the same expression - and also info elements in Field Maps may display differently - where you can also calculate an expression elsewhere and bring that into the info element.)

I am assuming you should be able to get your data similar to how you are above, but then build out your HTML when returning it as text.  I believe when you return text in a pop-up that is HTML formatted it should appear as HTML in most places, but not all places - I wouldn't ever guarantee the same behavior everywhere.

return { 
 	type : 'text', 
 	text : variable //this property supports html tags 
 }

Not sure if this was helpful or not, but I might be able to assist further if I knew where you were building this out.

Edit - If you add an Arcade pop-up in Web Map Viewer - you will end up with the return value I posted above.  I checked that the pop-up formats HTML in Field Maps and in Experience Builder - but oddly enough, it will not format it in the pop-up in Web Map Viewer itself. Might be a way to discern the context and return different types/values, but for Field Maps and Experience Builder - this might work.

MitchellGrafstein_0-1742586153772.png

I hope this helps.

Mitchell Grafstein, Horticultural Inspector 1, NYS Dept. of Agriculture and Markets
0 Kudos