I need help coding an indicator box to show some times. I would like it to look something like:
Start Time: <start time>
End Time: <end time>
Total Hours Worked: <hours>
I can get each part of the code to return, but not as a whole. Below is what I have so far, but it's only returning the Start Time
Solved! Go to Solution.
This is the code to put everything into a single FeatureSet.
var p = Portal("https://arcgis.com");
var poles = FeatureSetByPortalItem(p, 'f2180d9e68b3466ab042399a38aea2fd', 0);
var startTime = Min(poles, 'NewTime');
var endTime = Max(poles, 'NewTime');
var TimeElasped = DateDiff(endTime, startTime, 'hours');
var HoursWorked = Round(TimeElasped, 2);
var jsonDictionarySTART = {
fields: [{
alias: "STARTTIME",
name: "STARTTIME",
type: "esriFieldTypeDate",
},
{
alias: "ENDTIME",
name: "ENDTIME",
type: "esriFieldTypeDate",
},
{
alias: "TOTAL_TIME",
name: "TOTAL_TIME",
type: "esriFieldTypeDouble",
},
],
spatialReference: { wkid: 4326 },
geometryType: "esriGeometryPoint",
features: [{
geometry: {
spatialReference: { wkid: 4326 },
x: -151.0063,
y: 63.069,
},
attributes: {
STARTTIME: startTime,
ENDTIME: endTime,
TOTAL_TIME: HoursWorked
},
}]
};
return FeatureSet(Text(jsonDictionarySTART));
However, you can't have line breaks in an Indicator. You can put the individual items in the top, middle, and bottom text
Note: when posting code, use the Insert/Edit code sample button
The polesToday variable doesn't have the correct syntax for the SQL92 expression. That doesn't understand any of the Arcade functions, so you have to put that in via a variable. You can also combine your Filters into a single one, if you'd like.
var sql = `inspected_by = 'Codey Vaughn'
AND inspected_date > '${Today()}'`
var polesToday = Filter(poles, sql)
The code has to use "> Today", since the function Today returns the value "2024-02-06T00:00:00-05:00". Your dates also have a time component, which puts today's records after this value.
This is the code to put everything into a single FeatureSet.
var p = Portal("https://arcgis.com");
var poles = FeatureSetByPortalItem(p, 'f2180d9e68b3466ab042399a38aea2fd', 0);
var startTime = Min(poles, 'NewTime');
var endTime = Max(poles, 'NewTime');
var TimeElasped = DateDiff(endTime, startTime, 'hours');
var HoursWorked = Round(TimeElasped, 2);
var jsonDictionarySTART = {
fields: [{
alias: "STARTTIME",
name: "STARTTIME",
type: "esriFieldTypeDate",
},
{
alias: "ENDTIME",
name: "ENDTIME",
type: "esriFieldTypeDate",
},
{
alias: "TOTAL_TIME",
name: "TOTAL_TIME",
type: "esriFieldTypeDouble",
},
],
spatialReference: { wkid: 4326 },
geometryType: "esriGeometryPoint",
features: [{
geometry: {
spatialReference: { wkid: 4326 },
x: -151.0063,
y: 63.069,
},
attributes: {
STARTTIME: startTime,
ENDTIME: endTime,
TOTAL_TIME: HoursWorked
},
}]
};
return FeatureSet(Text(jsonDictionarySTART));
However, you can't have line breaks in an Indicator. You can put the individual items in the top, middle, and bottom text
Thanks for your help @KenBuja . This worked great. I thought that I would be able to filter the information within the indicator itself but was incorrect. I'm now trying to modify the code to filter by inspector and today's date. It's not giving any errors, but only returns null values. Any ideas on this?
Note: when posting code, use the Insert/Edit code sample button
The polesToday variable doesn't have the correct syntax for the SQL92 expression. That doesn't understand any of the Arcade functions, so you have to put that in via a variable. You can also combine your Filters into a single one, if you'd like.
var sql = `inspected_by = 'Codey Vaughn'
AND inspected_date > '${Today()}'`
var polesToday = Filter(poles, sql)
The code has to use "> Today", since the function Today returns the value "2024-02-06T00:00:00-05:00". Your dates also have a time component, which puts today's records after this value.
Thank you! This is working great!