|
POST
|
Hi @Anonymous User , One of the issues in your code is that you using "fs" as if it contains the installation date. In this case "fs" is a featureset and you will loop through the features, read out the installation date and and fill the output "Dict" with the values calculated. Have a look at the code below: var p = 'https://www.arcgis.com';
var itemId = 'xxx';
var layerId = 0;
var fs = Filter(FeatureSetByPortalItem(Portal(p), itemID, layerID,['Installation']),'Installation > 0');
var ageyrs = Year(Now())-fs;
var agechoice = iif(ageyrs>20,'>20 Years Old',(iif(ageyrs<10,'<10 Years Old','11-20 Years Old')));
var Dict = {
'fields':[
{'name': 'sign_age', 'type':'esriFieldTypeDouble'},
{'name': 'agecat', 'type':'esriFieldTypeString'}],
'geometryType':'',
'features': []};
var index = 0;
for (var f in fs) {
var instalationdate = f['Installation'];
var ageyrs = DateDiff(Now(), instalationdate, 'years');
var agechoice = iif(ageyrs>20,'>20 Years Old',
(iif(ageyrs<10,'<10 Years Old',
'11-20 Years Old')));
Dict.features[index] = {
'attributes': {
'sign_age': ageyrs,
'agecat': agechoice
}}
index++;
};
return FeatureSet(Text(Dict)); If you just want to return a count per age class you could also create an intermediate dictionary for each class value and update the count.
... View more
09-07-2021
10:56 AM
|
2
|
4
|
3171
|
|
POST
|
Hi @DeborahDAVID , From what I have seen we still don't have this functionality in Arcade today, but I agree with you that it would be great to have.
... View more
08-06-2021
07:16 AM
|
0
|
0
|
4079
|
|
POST
|
Hi @RyanElvrum2 , Do you have multiple meters for a single service account? If so, you will only get a single meter in the pop-up string. Also, the meter number does not need to be cast to string since this will always be a string when cascading a text with other information. Try this: var ServiceLocationGID = $feature.GlobalID;
var SqlServiceAccounts = "ServiceLocationGID = @ServiceLocationGID";
var ServiceAccounts = FeatureSetByName($map, "ServiceAccounts");
var RelatedServiceAccounts = Filter(ServiceAccounts, SqlServiceAccounts);
var Meters = FeatureSetByName($map, "Meters");
var popupstring = "";
for (var ServiceAccount in RelatedServiceAccounts){
popupstring += "First Name: " + Text(Proper(ServiceAccount.firstname)) + TextFormatting.Newline;
popupstring += "Last Name: " + Proper(ServiceAccount.lastname) + TextFormatting.Newline;
popupstring += "Service Address 1: " + Proper(ServiceAccount.serviceaddr1) + TextFormatting.Newline;
popupstring += "Service Address 2: " + Proper(ServiceAccount.serviceaddr2) + TextFormatting.Newline;
popupstring += "Account Number: " + ServiceAccount.AccountNumber + TextFormatting.Newline;
var ServiceAccountGID = ServiceAccount.GlobalID;
var SqlMeters = "ServiceAccountGID = @ServiceAccountGID";
var RelatedMeters = Filter(Meters, SqlMeters);
for (var Meter in RelatedMeters) {
popupstring += " - Meter Number: " + Meter.MeterID + TextFormatting.Newline;
}
popupstring += TextFormatting.Newline;
}
Return popupstring;
... View more
08-03-2021
07:53 AM
|
1
|
2
|
7334
|
|
POST
|
Hi @RyanElvrum2 , I am afraid that is true. This function was introduced at version 1.8 of Arcade and Enterprise 10.7.1 has version 1.7 of Arcade. Your initial code that uses a Filter function and a SQL query would be the right way to go. And when nesting this twice you should be able to get to the meter information. An example of this is shown below: // Service Location (Point feature) --> Service Account (Table) --> Meters (Table)
// get the value of the service location feature that connects to the service accounts
var ServiceLocationValueToQueryFor = $feature["FieldNameServiceLocationValue"];
// create SQL expression
var SqlServiceAccounts = "SomeField = @ServiceLocationValueToQueryFor";
// filter the related service accounts
var ServiceAccounts = FeatureSetByName($map, "Name of the ServiceAccounts table in the map");
var RelatedServiceAccounts = Filter(ServiceAccounts, SqlServiceAccounts);
// loop through the service accounts
var Meters = FeatureSetByName($map, "Name of the Meters table in the map");
for (var ServiceAccount in RelatedServiceAccounts) {
// include info of the service account?
var MeterValueToQueryFor = ServiceAccount["FieldNameMaterValue"];
var SqlMeters = "SomeField = @MeterValueToQueryFor";
// use the service account to drill down to the meter information
var RelatedMeters = Filter(Meters, SqlMeters);
// loop through the meters
for (var Meter in RelatedMeters) {
// do something with the meter information
}
}
... View more
08-02-2021
09:58 AM
|
1
|
5
|
7411
|
|
POST
|
Hi @RyanElvrum2 , I would probably use a nested FeatureSetByRelationshipName function like this if you have a nested relationship: // Service Location (Point feature) --> Service Account (Table) --> Meters (Table)
// get the feature, which is the service location
var servicelocation = $feature;
// use the service location and the relationship to drill down to service accounts
var serviceaccounts = FeatureSetByRelationshipName(servicelocation, "Relationship name for Service Location to Service Account", ['*'], false);
// loop through the service accounts
for (var serviceaccount in serviceaccounts) {
// include info of the service account?
// use the service account to drill down to the meter information
var meters = FeatureSetByRelationshipName(serviceaccount, "Relationship name for Service Account to Meters", ['*'], false);
// loop through the meters
for (var meter in meters) {
// do something with the meter information
}
}
... View more
08-02-2021
09:05 AM
|
0
|
7
|
7425
|
|
POST
|
Hi @Anonymous User , I just posted a workaround and I also noticed that the order of the dictionary is alphabetically and not the order as one defines it.
... View more
07-07-2021
09:22 AM
|
1
|
1
|
3437
|
|
POST
|
Hi @Anonymous User , A simple fix could be this: // create a disctionary with field names and month names (change the field names!)
var dct = {"OpenJan": "January", "OpenFeb": "February",
"OpenMar": "March", "OpenApr": "April",
"OpenMay": "May", "OpenJun": "June",
"OpenJul": "July", "OpenAug": "August",
"OpenSep": "September", "OpenOct": "October",
"OpenNov": "November", "OpenDec": "December"};
// simple fix, use a list of field names with the right order
var lst = ["OpenJan", "OpenFeb", "OpenMar", "OpenApr",
"OpenMay", "OpenJun", "OpenJul", "OpenAug",
"OpenSep", "OpenOct", "OpenNov", "OpenDec"];
// start with an empty result string
var result = "OK";
// start with an empty result string
var result = "";
// loop through the list of field names
for (var i in lst) {
var fldname = lst[i];
// read the value of the field
var fldval = $feature[fldname];
// validate if the value is YES
if (fldval == "YES") {
// add the month to the result
if (result == "") {
// first month
result = dct[fldname];
} else {
// any next month
result += ", " + dct[fldname];
}
}
}
return result;
... View more
07-07-2021
09:18 AM
|
0
|
0
|
3438
|
|
POST
|
Hi @Anonymous User , Can you share the expression you have now?
... View more
07-07-2021
09:10 AM
|
0
|
4
|
3439
|
|
POST
|
Hi @Anonymous User , Glad to hear that it helped. If you run into problems with making the required changes just let me know. About your questions: For example, why use this method instead of creating an entire new feature? I wonder how you would create a new feature if you are not the owner of the data. You could with a notebook access the data, transform it the way you need it, and write a local feature layer and use that. This is more complex to implement. What was the purpose of starting the logic part of the expression with "an empty results string?" Any variable you want to assign a value needs to be initialized. This is done using "var NameOfVariable = InitialValue". Perhaps this could be omitted and line 21 could start with "var ". However, sometimes this could create an error when compiling the code, so I prefer to initialize the variable before the loop. Finally, what exactly do the "{" and "}" symbols do in this expression? The "{" and "}" are used to contain logic that needs to be executed. It also helps the readability of the code. To learn more about Arcade you could follow the learn path: https://learn.arcgis.com/en/paths/try-arcade/
... View more
07-07-2021
08:55 AM
|
1
|
6
|
3443
|
|
POST
|
Hi @Anonymous User , I think you could use something like this: // create a disctionary with field names and month names (change the field names!)
var dct = {"OpenJan": "January", "OpenFeb": "February",
"OpenMar": "March", "OpenApr": "April",
"OpenMay": "May", "OpenJun": "June",
"OpenJul": "July", "OpenAug": "August",
"OpenSep": "September", "OpenOct": "October",
"OpenNov": "November", "OpenDec": "December"};
// start with an empty result string
var result = "";
// loop through field names in dct
for (var fldname in dct) {
// read the value of the field
var fldval = $feature[fldname];
// validate if the value is YES
if (fldval == "YES") {
// add the month to the result
if (result == "") {
// first month
result = "Open in: " + dct[fldname];
} else {
// any next month
result += ", " + dct[fldname];
}
}
}
return result;
... View more
07-07-2021
07:51 AM
|
1
|
8
|
3450
|
|
POST
|
Hi @kmsmikrud , As far as I can tell Arcade does not have access to how a user has connected to the application. You will probably need a custom JavaScript application to use the solution provided by your coworker.
... View more
06-16-2021
01:27 PM
|
0
|
1
|
1275
|
|
POST
|
Hi @kmsmikrud , When I use a for loop I normally declare the variable outside the loop and adjust it inside the loop. In this case, we don't have a for loop and can simply declare the variable when we assign the first content to it.
... View more
06-11-2021
12:23 PM
|
1
|
0
|
2366
|
|
POST
|
Hi @kmsmikrud , Sorry for the delay. Can you try the following and see if it works? // can you validate if the query is valid?
var dt_query0503 = "CreationDate <= timestamp '2021-05-04 07:59:59' AND CreationDate >= timestamp '2021-05-03 08:00:00'";
var dt_query0504 = "CreationDate <= timestamp '2021-05-05 07:59:59' AND CreationDate >= timestamp '2021-05-04 08:00:00'";
var dt_query0505 = "CreationDate <= timestamp '2021-05-06 07:59:59' AND CreationDate >= timestamp '2021-05-05 08:00:00'";
var dt_query0506 = "CreationDate <= timestamp '2021-05-07 07:59:59' AND CreationDate >= timestamp '2021-05-06 08:00:00'";
// access the layer and intersect it a single time with the feature
// and only retrieve the attribute you need
var fs = Intersects(FeatureSetByName($map, "Herring School:", ["FINAL_BIO"], False), $feature);
var sec_dt03_schools = Filter(fs, dt_query0503);
var sec_dt04_schools = Filter(fs, dt_query0504);
var sec_dt05_schools = Filter(fs, dt_query0505);
var sec_dt06_schools = Filter(fs, dt_query0506);
// do the Sum on the featuresets from the previous step
var FB_03 = Round(Sum(sec_dt03_schools, "FINAL_BIO"), 2);
var FB_04 = Round(Sum(sec_dt04_schools, "FINAL_BIO"), 2);
var FB_05 = Round(Sum(sec_dt05_schools, "FINAL_BIO"), 2);
var FB_06 = Round(Sum(sec_dt06_schools, "FINAL_BIO"), 2);
// create the result string
var result = "5/3/21: " + FB_03;
result += TextFormatting.NewLine + "5/4/21: " + FB_04;
result += TextFormatting.NewLine + "5/5/21: " + FB_05;
result += TextFormatting.NewLine + "5/6/21: " + FB_06;
// return the result
return result;
... View more
06-04-2021
03:02 PM
|
0
|
2
|
2419
|
|
POST
|
Hi @PaulSweeney3 , Not sure if this will work, but from what I can deduce from what you did it could be something like this: var id = $feature.ID;
var sql = "ID LIKE '" + Left(id, Count(id)-1) + "%'"; // ignore this
var fs = OrderBy(Filter($layer, sql),'ID ASC');
var TotalPoly = [];
var i = 0;
for (var feat in fs) {
var pnts = Geometry(feat)["paths"][0];
for (var p in pnts) {
TotalPoly[i++] = pnts[p].y + " " + pnts[p].x;
}
}
return Concatenate(TotalPoly, ";"); I am sure there must be a limit on the length of the URL, but not sure what it is... You can round the coordinates, but this will affect the precision of the geometry that results.
... View more
06-04-2021
02:40 PM
|
1
|
0
|
2029
|
| Title | Kudos | Posted |
|---|---|---|
| 6 | 12-20-2019 08:41 AM | |
| 1 | 01-21-2020 07:21 AM | |
| 2 | 01-30-2020 12:46 PM | |
| 1 | 05-30-2019 08:24 AM | |
| 1 | 05-29-2019 02:45 PM |
| Online Status |
Offline
|
| Date Last Visited |
11-26-2025
02:43 PM
|