Hi,
I've been struggling to find a reference to enable a constraint attribute rule that only allows users to input text as "##-#####-##" for a specific text field. I'm happy to have the user input this manually or have the dashes automatically put in.
I tried the below:
text($feature.accountname, '##-#####-##')
I'm avoiding creating a new field to perform a calculation rule as I can't really change the schema at this current time due to connected services.
Would appreciate any and all help
Solved! Go to Solution.
Don't do it as constraint rule, but as calculation rule on accountname:
// Calculation attribute rule
// Field acccountname
// Triggers: Insert, Update
if(IsEmpty($feature.accountname)) {
return null
}
var input = Replace($feature.accountname, "-", "")
return Left(input, 2) + "-" + Mid(input, 2, 5) + "-" + Right(input, 2)
To ensure that this calculates correct values, you can do a constraint rule that checks for the length of the string:
// Constraint attribute rule
// rejects the edit if there are not exactly 9 characters
var input = Replace($feature.accountname, "-", "")
return Count(input) == 9
Don't do it as constraint rule, but as calculation rule on accountname:
// Calculation attribute rule
// Field acccountname
// Triggers: Insert, Update
if(IsEmpty($feature.accountname)) {
return null
}
var input = Replace($feature.accountname, "-", "")
return Left(input, 2) + "-" + Mid(input, 2, 5) + "-" + Right(input, 2)
To ensure that this calculates correct values, you can do a constraint rule that checks for the length of the string:
// Constraint attribute rule
// rejects the edit if there are not exactly 9 characters
var input = Replace($feature.accountname, "-", "")
return Count(input) == 9
Thank you! I did not think to use replace in a calculation.