Select to view content in your preferred language

Constraint rule field length

459
2
Jump to solution
05-26-2022 09:27 AM
V1212
by
Emerging Contributor

Hi, I created a constraint that checks if an editor has entered a valid number into a field (length of 12). 

var length = Count(Text($feature.name_id));

if  ((($feature.name_id!=$originalfeature.name_id) && (length!=12)) 

{return false}

else

{return true}

 

I want to modify this rule so that an editor can remove an incorrect 12 char text from the field without the rule getting triggered. I've tried different variations of this expression but it doesn't work as intended. I get an error message when I try to blank the field. 

 

var length = Count(Text($feature.name_id));

if  (($feature.name_id!=$originalfeature.name_id) && ((length!=12) || IsEmpty(length)))

{return false}

else

{return true}

 

Thanks in advance! 

 

0 Kudos
1 Solution

Accepted Solutions
JohannesLindner
MVP Frequent Contributor

It's probably because you're checking length for null, not name_id.

 

As a side note: just use multiple if statements. Your statement is hard to read and understand because of all the parantheses in there, and the $feature stuff doesn't help...

var name_id = $feature.name_id
var o_name_id = $originalfeature.name_id

if(name_id == o_name_id) { // you're not changing it
    return true
}
if(IsEmpty(name_id)) { // it's blank
    return true
}
var len = Count(Text(name_id))
return len == 12

 


Have a great day!
Johannes

View solution in original post

2 Replies
JohannesLindner
MVP Frequent Contributor

It's probably because you're checking length for null, not name_id.

 

As a side note: just use multiple if statements. Your statement is hard to read and understand because of all the parantheses in there, and the $feature stuff doesn't help...

var name_id = $feature.name_id
var o_name_id = $originalfeature.name_id

if(name_id == o_name_id) { // you're not changing it
    return true
}
if(IsEmpty(name_id)) { // it's blank
    return true
}
var len = Count(Text(name_id))
return len == 12

 


Have a great day!
Johannes
V1212
by
Emerging Contributor

Thanks for the help and your tip! 

0 Kudos