Snippets

Adaptavist Adaptavist ScriptRunner for Jira Cloud Example Workflow Validators

Updated by Kristian Walker

File ScriptRunnerforJiraCloudExampleWorkflowValidatorss.groovy Modified

  • Ignore whitespace
  • Hide word diff
 issue.issueType.name.match('^(<IssueTypeHere>)$') != null && user.getProjectRoles(project).map(p => p.name).includes("<ProjectRoleHere>") || issue.issueType.name.match('^(<IssueTypeHere>|<IssueTypeHere>)$') != null //You may also want to set the Error message to have text similar to 'You must be in the X Project Role to create the X Issue Type'
 
 
+// Validate that one of two label fields must have a value 
+// Note: You should replace 'customfield_10099' and 'customfield_10100' in the example below with the ID's of the label fields inside of your instance. 
+issue.customfield_10099 !=null || issue.customfield_10100 !=null //You may also want to set the Error message to have text similar to 'You must specify a value in one of the label fields'
 
 
 
Updated by Kristian Walker

File ScriptRunnerforJiraCloudExampleWorkflowValidatorss.groovy Modified

  • Ignore whitespace
  • Hide word diff
 // The stories paramater returns all the issues below the Epic issue to allow there status to be checked. 
 issue.isEpic && issue.stories.filter(story => story.status.name == 'Done').length == issue.stories.length //You may also want to set the Error message to have text similar to 'You must ensure all issues inside the Epic are in the Done status before the Epic issue can be closed'
 
+// Validate that only users in a specific project role can create an issue of a certain type
+// The first expression mandates the issue type must be a specific issue type.
+// The second expression joined by the && operator mandates that the user must be in a specific project role to create the issue type from expression1
+// The third expression specifies that all other issue types used by the project can be created. add new issue types by adding them in and seperating them with a | character
+issue.issueType.name.match('^(<IssueTypeHere>)$') != null && user.getProjectRoles(project).map(p => p.name).includes("<ProjectRoleHere>") || issue.issueType.name.match('^(<IssueTypeHere>|<IssueTypeHere>)$') != null //You may also want to set the Error message to have text similar to 'You must be in the X Project Role to create the X Issue Type'
+
+
+
+
 
Updated by Kristian Walker

File ScriptRunnerforJiraCloudExampleWorkflowValidatorss.groovy Modified

  • Ignore whitespace
  • Hide word diff
 // Validate that all issues below an Epic must be in the Done status before the Epic issue itself can be closed.
 // The isEpic paramater returns true if the issue is an Epic and false if it is any other issue type
 // The stories paramater returns all the issues below the Epic issue to allow there status to be checked. 
-
 issue.isEpic && issue.stories.filter(story => story.status.name == 'Done').length == issue.stories.length //You may also want to set the Error message to have text similar to 'You must ensure all issues inside the Epic are in the Done status before the Epic issue can be closed'
 
 
Updated by Kristian Walker

File ScriptRunnerforJiraCloudExampleWorkflowValidatorss.groovy Modified

  • Ignore whitespace
  • Hide word diff
 // This validator will also work on the Create transition as well.
 issue.attachments.filter(attachment => attachment.id == null).length ==3 // You may also want to set the Error message to have text similar to 'You must upload 3 attachments.'
 
+// Validate that all issues below an Epic must be in the Done status before the Epic issue itself can be closed.
+// The isEpic paramater returns true if the issue is an Epic and false if it is any other issue type
+// The stories paramater returns all the issues below the Epic issue to allow there status to be checked. 
+
+issue.isEpic && issue.stories.filter(story => story.status.name == 'Done').length == issue.stories.length //You may also want to set the Error message to have text similar to 'You must ensure all issues inside the Epic are in the Done status before the Epic issue can be closed'
+
 
Updated by Kristian Walker

File ScriptRunnerforJiraCloudExampleWorkflowValidatorss.groovy Modified

  • Ignore whitespace
  • Hide word diff
 // Validate that a set number of new attachments must be uploaded during the transition.  
 // The example below mandates that 3 new attachments must be uploaded on the transition screen.  
 // This validator will also work on the Create transition as well.
-issue.attachments.filter(a => a.id == null).length ==3 // You may also want to set the Error message to have text similar to 'You must upload 3 attachments.'
+issue.attachments.filter(attachment => attachment.id == null).length ==3 // You may also want to set the Error message to have text similar to 'You must upload 3 attachments.'
 
 
  1. 1
  2. 2
  3. 3
HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.