Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
titleSIL Code
string[] statuses = {"Opened", "Reopened"};
string errorMsg = "Parent issue should have status Opened or Reopened!";
if(!isNull(parent) && !elementExists(statuses, parent.status)) {
   return false, errorMsg;
}

Validation based on regular expression

A SIL validator which checks if a text field matches a regular expression (eg for a social number):

Code Block
titleSIL Code
string errorMsg = "Invalid social number format.";
string REGEXP = "^\\d{3}-\\d{2}-\\d{4}$"; 
if(!matches(customfield_10100, REGEXP)) {
   return false, "customfield_10100", errorMsg;
}

Validation on linked issues

Blocking Start Progress transition whenever current issue has a link of type Blocks with an issue in a status different from Resolved and Closed:

...

Code Block
titleSIL Code
string errorMsg = "There are still unclosed issues in the current project.";
string[] issues = selectIssues("project = " + project + " AND status != Closed AND key != " + key);
if(size(issues) > 0) {
   return false, errorMsg;
}

Validation based on mathematical or date-time expression

A SIL validator which checks if a numeric custom field is greater than or equal to 0:

Code Block
titleSIL Code
string errorMsg = "The number should be greater or equal to 0";
if(sign(customfield_10101) == -1) {
   return false, "customfield_10101", errorMsg;
}

The sign routine determines the sign of a number. It returns 1 if the number is positive, zero (0) if the number is 0, and -1 if the number is negative.

More useful mathematical routines can be found in the Math Routines section.

A SIL validator which checks if due date is before current date:

Code Block
titleSIL Code
string errorMsg = "The due date of the issue was exceeded!";
if(dueDate < currentDate()) {
   return false, "duedate", errorMsg;
}

More useful date routines can be found in the Date Routines section.

Compare two parsed texts

A SIL validator which checks if description contains summary:

...