Select to view content in your preferred language

Data validation with arcade

1107
5
Jump to solution
01-09-2024 06:57 AM
ShaiBravo
Occasional Contributor

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!

Tags (3)
2 Solutions

Accepted Solutions
KenBuja
MVP Esteemed Contributor

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)

 

View solution in original post

0 Kudos
ShaiBravo
Occasional Contributor

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')

View solution in original post

0 Kudos
5 Replies
KenBuja
MVP Esteemed Contributor

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)

 

0 Kudos
ShaiBravo
Occasional Contributor

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')

0 Kudos
KenBuja
MVP Esteemed Contributor

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.

0 Kudos
ShaiBravo
Occasional Contributor

Sorry, I was all turned around. I input the correct field which is a string and it worked! Thanks a ton.

0 Kudos
KenBuja
MVP Esteemed Contributor

Glad to help. Don't forget to click the Accept as Solution button on the post that answered your question.

0 Kudos