Return "Valid" if the custom field value matches the regular expression and "Invalid" if it does not.
Configuration
Create a Custom smart text field and use the General parsing mode.
Expression
%{matches(%{issue.cfnnnnn},"6|7|8|9") ? "Valid":"Invalid"}
The values entered as arguments in the matches() parser function can be replaced with different values or with a regular expressions to validate differently the value of the custom field.
Please, note that it is necessary to replace nnnnn with the ID of the custom field.
Used parser functions
The links lead to the JWTC documentation because the parser functions are shared functionalities.
Details
1. What does the expression do?
The expression checks the value of a specific custom field in a work item. If the value matches certain values (in this case, if it contains "6", "7", "8", or "9"), it returns "Valid". If it does not match, it returns "Invalid".
2. Step-by-step breakdown
Let’s break it down:
-
%{issue.cfnnnnn}: This retrieves the value of a custom field from the work item. You need to replacennnnnwith the actual ID of your custom field. -
matches(value, "6|7|8|9"): This function checks if the value contains any of the numbers 6, 7, 8, or 9. The"6|7|8|9"part is a regular expression, where the|symbol means "or". -
? "Valid" : "Invalid": This is a conditional statement. If thematches()function finds a match, it returns "Valid". If not, it returns "Invalid".
3. Examples
-
If the custom field value is "8", the expression returns "Valid".
-
If the custom field value is "5", the expression returns "Invalid".
-
If the custom field value is "79", the expression returns "Valid" (because it contains "7" and "9").
-
If the custom field value is "123", the expression returns "Invalid" (because it does not contain 6, 7, 8, or 9).
4. Real-life use cases
-
Data validation: You want to ensure that a custom field in your work items only contains certain values (for example, only numbers 6, 7, 8, or 9 are allowed for a specific process).
-
Quality control: Automatically mark work items as "Valid" or "Invalid" based on the content of a custom field, helping users quickly identify which items meet your criteria.