...
Code Block |
---|
|
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
The below example shows a SIL validator which forces a custom field to be required in resolve screen only if the resolution was set to 'Fixed':
Code Block |
---|
|
string errorMsg = "To resolve the issue as 'Fixed' you should give a value to field 'Color'.";
if(!hasInput("customfield_10000")) {
return false, "customfield_10000", 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 |
---|
|
string errorMsg = "Progress can't start because there is at least one blocking issue.";
string[] statuses = {"Resolved", "Closed"};
string[] blockingIssues = linkedIssues(key, "Blocks");
for(string issue in blockingIssues) {
if(!elementExists(statuses, %issue%.status)) {
return false, errorMsg;
}
} |
Forbidding issue links of types Blocks and Cloners with issues of type Bug:
Code Block |
---|
|
string errorMsg = "Issue links of types 'Blocks' and 'Cloners' with 'Bugs' are forbidden.";
string[] links = {"Blocks", "Cloners"};
for(string link in links) {
string[] linkedIssues = linkedIssues(key, link);
for(string issue in linkedIssues) {
if(%issue%.issueType == "Bug") {
return false, errorMsg;
}
}
} |
Validation on non-linked issue
Preventing a transition from being executed if the rest of issues in the project aren't closed:
Code Block |
---|
|
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;
} |
Compare two parsed texts
A SIL validator which checks if description contains summary:
Code Block |
---|
|
string errorMsg = "Description must contain summary";
if(!contains(description, summary)) {
return false, "description", errorMsg;
} |
Users in a field are/aren't in a project role
A SIL validator which checks if users selected in a multi user picker custom field are in a given project role:
Code Block |
---|
|
string PROJECT_ROLE = "Developers";
for(string user in customfield_10500) {
if(!isUserInRole(user, project, PROJECT_ROLE)) {
string errorMsg = "User " + user + " is not in project role " + PROJECT_ROLE;
return false, "customfield_10500", errorMsg;
}
} |
A custom field is/isn't initialized
A SIL validator which checks if a custom field is initialized during transaction:
Code Block |
---|
|
string errorMsg = "Field was not initialized!";
if(!hasInput("customfield_10500")) {
return false, "customfield_10500", errorMsg;
} |
Check user property
A SIL validator which checks if a user property has a certain value:
Code Block |
---|
|
string COUNTRY = "Romania";
string errorMsg = "Assignee country must be " + COUNTRY;
if(getUserProperty(assignee, "country") != COUNTRY) {
return false, "assignee", errorMsg;
} |