Hi there,
I am trying to use attribute rules with Arcade to automate a field when a new attribute is added to my map. I figured out the first part to get my file number to generate:
var date = $feature.date_issued
var year = Text(Year(date), '0000');
var month = Text(Month(date), '00');
var day = Text(Day(date), '00');
var fileNumber = year + month + day;
return fileNumber;
What I can't seem to figure out is how to validate if that number already exisits in another attribute, and if it does, how to return filenumber + A or +B if A exisits as well. Please let me know if this is possible to do or if I will have to find another way to do it.
Thanks!
Solved! Go to Solution.
This would check whether that value exists and append either an A or B. Don't forget to replace "theField" with the appropriate field name.
var date = $feature.date_issued
var year = Text(Year(date), '0000');
var month = Text(Month(date), '00');
var day = Text(Day(date), '00');
var fileNumber = year + month + day;
var fileNumberA = `${fileNumber}A`
when (Count(Filter($featureSet, "theField = @fileNumberA")) > 0, `${fileNumber}B`,
Count(Filter($featureSet, "theField = @fileNumber")) > 0, fileNumberA,
fileNumber)
Thanks for the reply, not sure if I am doing something incorrect, but when I use the following code, I get the following error returned:
var yearn = Text(Now(), 'YYYY');
var monthn = Text(Now(), 'MM');
var dayn = Text(Now(), 'DD');
var fileNumber = yearn + monthn + dayn;
var fileNumberA = `${fileNumber}A`
when (Count(Filter($featureSet, "date_issued = @fileNumberA")) > 0, `${fileNumber}B`,
Count(Filter($featureSet, "date_issued = @fileNumber")) > 0, fileNumberA,
fileNumber)
Invalid expression.
Error on line 7.
Invalid where clause (date_issued = '20240109A')
This would check whether that value exists and append either an A or B. Don't forget to replace "theField" with the appropriate field name.
var date = $feature.date_issued
var year = Text(Year(date), '0000');
var month = Text(Month(date), '00');
var day = Text(Day(date), '00');
var fileNumber = year + month + day;
var fileNumberA = `${fileNumber}A`
when (Count(Filter($featureSet, "theField = @fileNumberA")) > 0, `${fileNumber}B`,
Count(Filter($featureSet, "theField = @fileNumber")) > 0, fileNumberA,
fileNumber)
Thanks for the reply, not sure if I am doing something incorrect, but when I use the following code, I get the following error returned:
var yearn = Text(Now(), 'YYYY');
var monthn = Text(Now(), 'MM');
var dayn = Text(Now(), 'DD');
var fileNumber = yearn + monthn + dayn;
var fileNumberA = `${fileNumber}A`
when (Count(Filter($featureSet, "date_issued = @fileNumberA")) > 0, `${fileNumber}B`,
Count(Filter($featureSet, "date_issued = @fileNumber")) > 0, fileNumberA,
fileNumber)
Invalid expression.
Error on line 7.
Invalid where clause (date_issued = '20240109A')
What type of field is "date_issued"? In your first post, it looks like it's a date field. If that's so, then you can't use a string to query it or to put in the result ('20240109A'). I successfully tested my code on a string field.
Sorry, I was all turned around. I input the correct field which is a string and it worked! Thanks a ton.
Glad to help. Don't forget to click the Accept as Solution button on the post that answered your question.