Select to view content in your preferred language

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

595
1
06-01-2023 12:09 AM
Labels (1)
LindsayRaabe_FPCWA
Honored 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
1 Reply
LindsayRaabe_FPCWA
Honored 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