POST
|
You can check if those values are empty before doing your calculations var Status = $datapoint.OutageStatus;
var Off = $datapoint.DateOff;
var On = $datapoint.DateRelightComplete;
var HoursOff;
if (IsEmpty(On) || IsEmtpy(Off)) {
HoursOff = 0;
} else {
HoursOff = Round(DateDiff(On, Off, 'hours'), 1);
}
return {
textColor: '',
backgroundColor: '',
separatorColor:'',
selectionColor: '',
selectionTextColor: '',
attributes: {
HoursOff:HoursOff,
}
} or you can use the IsNan function afterward var Status = $datapoint.OutageStatus
var Off = $datapoint.DateOff
var On = $datapoint.DateRelightComplete
var DaysOff = DateDiff (On, Off, 'hours')
var HoursOff = Round(DaysOff,1)
if (IsNan(HoursOff)) HoursOff = 0;
... View more
3 weeks ago
|
1
|
0
|
211
|
POST
|
If you want the hours just rounded to something like 2.5, use Round function (and template literals) return `${Round(TimeDiff - HoursOff, 1)} hours` You can add this to return the hours and minutes var TotalTime = TimeDiff - HoursOff
var Hours = Floor(TotalTime);
var Minutes = Floor((TotalTime - Hours) * 60)
return `${Hours} hours and ${Minutes} minutes`
... View more
3 weeks ago
|
0
|
0
|
95
|
POST
|
There is a for await...of loop that you can use in this case.
... View more
3 weeks ago
|
1
|
1
|
322
|
POST
|
This should work. It calculates the number of days between the start date and end date and subtracts 15 hours for each day. var StartDate = $feature.TimeStart
var EndDate = $feature.TimeEnd
var TimeDiff = DateDiff(EndDate, StartDate, 'hours')
var DayDiff = DateDiff(DateOnly(EndDate), DateOnly((StartDate)), 'days')
var HoursOff = 15 * DayDiff
return TimeDiff - HoursOff
... View more
3 weeks ago
|
0
|
2
|
106
|
POST
|
Your loops (and you only need one instead of two) aren't getting the attribute from the feature correctly. It should be like this var Owners = FEATURESETBYNAME($DATASTORE,"Owners",["TractID","Contacted"])
var ID = $feature.TractID
var OwnerID = Filter(Owners,"TractID=@ID")
var Cont = 0
var NCont =0
for(var f in OwnerID) {
if(f.Contracted == 'Yes') {
Cont +=1
} else if(f.Contracted == 'No') {
NCont +=1
}
}
if (Cont == 0 && NCont == 0) return null
return Cont/(Cont+NCont) I also added a check to make sure you're not dividing by zero.
... View more
3 weeks ago
|
0
|
1
|
112
|
POST
|
You're missing the URL for that sample: https://github.com/Esri/arcgis-pro-sdk-community-samples/tree/master/Map-Exploration/WorkingWithQueryDefinitionFilters
... View more
3 weeks ago
|
1
|
0
|
94
|
POST
|
There is a GitHub repository of many Arcade expressions. This one shows how to combine multiple layers for use in a Dashboard
... View more
3 weeks ago
|
0
|
0
|
86
|
POST
|
You can use the Schema function to get the domain information for all the fields. This code gives you an array of an array of the fields and their codedValue domain names. var dict = Schema($feature);
var fieldsArray = dict.fields;
var domainsArray = [];
for (var i in fieldsArray) {
if (HasValue(fieldsArray[i], 'domain')) {
if (HasValue(fieldsArray[i].domain, 'codedValues')) {
var domainArray = [fieldsArray[i].name]
for (var d in fieldsArray[i].domain['codedValues']) {
Push(domainArray, fieldsArray[i].domain['codedValues'][d].name)
}
Push(domainsArray,domainArray)
}
}
}
return domainsArray
... View more
3 weeks ago
|
1
|
1
|
84
|
POST
|
The code does work substituting my own portal item. Where is it breaking for you? Are you checking the output at various places in the code with Console to see if it's returning what you're expecting? var p = Portal("https://noaa.maps.arcgis.com/");
var fs = FeatureSetByPortalItem(
p,
'1624f1a86dca4af086cc13141a1b0e2b',
1,
['Authors'],
false
);
// Create empty array for features and feat object
var features = [];
var feat;
// Split comma separated hazard types and store in dictionary.
for (var feature in fs) {
var split_array = Split(feature["Authors"], ',')
var count_arr = Count(split_array)
console(count_arr)
for(var i = 0; i < count_arr; i++ ){
feat = {
'attributes': {
'split_choices': Trim(split_array[i])
}
}
Push(features, feat);
}}
// Empty dictionary to capture each hazard reported as separate rows.
var choicesDict = {
'fields': [
{ 'name': 'split_choices', 'type': 'esriFieldTypeString'}],
'geometryType': '',
'features': features
};
// Convert dictionary to featureSet.
var fs_dict = FeatureSet(choicesDict);
//return fs_dict
// Return featureset after grouping by hazard types.
return GroupBy(fs_dict, ['split_choices'],
[{ name: 'split_count', expression: 'split_choices', statistic: 'COUNT' }]);
... View more
3 weeks ago
|
0
|
0
|
108
|
POST
|
You can't directly compare the epoch number to a Date like that. You'll have to convert it to a Date. Arcade can create a Date from an epoch number, it must be in milliseconds (adding "000" to your attributes). For example: Date(1709269260) = Jan 20, 1970, 1:47:49 PM Eastern Standard Time Date(1709269260000) = Mar 1, 2024, 12:01:00 AM Eastern Standard Time If you want to use that field, then your expression should look like this var started = Date($feature.closureStartEpoch + '000');
var closed = Date($feature.closureEndEpoch + '000');
var present = Date()
If (present >= started && present <= closed) return "Open"
return "Closed"
... View more
3 weeks ago
|
0
|
1
|
108
|
POST
|
You can use the Left function if (Left($feature.ConduitSize, 6) == '1x1.25') return $feature.ClengthFt
... View more
3 weeks ago
|
1
|
0
|
161
|
POST
|
That's not an error, but a warning. You shouldn't use reserved words as variable names. It will still work, but it might cause problems.
... View more
3 weeks ago
|
0
|
2
|
122
|
POST
|
Unfortunately, you can't set the symbology directly through Arcade. You have to go into the Styles editor and change the colors for each of the returned values. You can simplify the code this way. var values = [10, 20, 30, 40, 50, 60, 90, 130, 150, 170, 210]
IIf(IndexOf(values, $feature.Color) > -1, $feature.Layer, 'Error')
... View more
3 weeks ago
|
1
|
0
|
79
|
POST
|
Unfortunately, the Map Viewer doesn't support label formatting tags in Arcade
... View more
3 weeks ago
|
0
|
1
|
144
|
Title | Kudos | Posted |
---|---|---|
2 | Friday | |
1 | Friday | |
1 | Tuesday | |
1 | Tuesday | |
1 | 11-06-2023 09:43 AM |
Online Status |
Offline
|
Date Last Visited |
9 hours ago
|