This section provides information on useful ScriptRunner solutions for Issue Templates.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.CustomFieldManager
CustomFieldManager cfm = ComponentAccessor.getCustomFieldManager();
CustomField tempalteCF = cfm.getCustomFieldObject(10112L);
log.error('[LOG] tempalteCF: ' + tempalteCF)
Map templateValue = issue.getCustomFieldValue(tempalteCF)
log.error('[LOG] templateValue: ' + templateValue)
boolean templateIsEmpty = templateValue.get("SELECTED_TEMPLATE") == null;
if (templateIsEmpty) {
log.error("Tempalte is empty")
return false;
}
log.error("Tempalte is not empty")
return true;
You need to replace 10112 in the line CustomField tempalteCF = cfm.getCustomFieldObject(10112L);
with your Template field’s ID.
import com.onresolve.jira.groovy.user.FormField
FormField templateVisibilityFormField = getFieldById("customfield_12800")
String optionName = templateVisibilityFormField.getValue();
FormField tempalteFormField = getFieldById("issue-templates-field");
if (optionName.equals("Two (hide template)")) {
tempalteFormField.setHidden(true)
} else {
tempalteFormField.setHidden(false)
}
Open the Validators tab and add the Simple scripted validator ScriptRunner.
As a condition, add the script below.
The code for this solution provides:
An algorithm for hiding a field (by Behaviours):
Two (hide template)
in this single select (12800) field, the template field (10112) will be hidden.Two (hide template)
in the single select (12800) field, then the field will be visible.An algorithm for validating the template field (by Simple scripted validator from ScriptRunner):
Two (hide template)
and the template (10112) field is empty, then no validation error is raised - like in this validation case above.Two (hide template)
, the template (10112) field will be mandatory - the validating script will raise an error when there is no selected template in the template (10112) field.import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.CustomFieldManager
CustomFieldManager cfm = ComponentAccessor.getCustomFieldManager();
CustomField templateCF = cfm.getCustomFieldObject(10112L);
CustomField templateVisibilityCF = cfm.getCustomFieldObject(12800L)
log.error('templateCF: ' + templateCF)
log.error('templateVisibilityCF: ' + templateVisibilityCF)
Map templateValue = issue.getCustomFieldValue(templateCF)
log.error('templateValue: ' + templateValue)
String templateVisibilityValue = issue.getCustomFieldValue(templateVisibilityCF)
log.error('templateVisibilityValue: ' + templateVisibilityValue)
boolean shouldBeOptional = "Two (hide template)".equals(templateVisibilityValue);
boolean templateIsEmpty = templateValue.get("SELECTED_TEMPLATE") == null;
if (!shouldBeOptional && templateIsEmpty) {
log.error("Template is empty")
return false;
}
log.error("Template is not empty")
return true;
This section provides information on Groovy integration
You can obtain the id of the used template in Groovy using provided service as on the code below.
All scripts have been tested on ScriptRunner 4.3.12.
Remember to add the annotation @WithPlugin("com.intenso.jira.issue-templates")
to use Issue Templates for Jira app.
import pl.intenso.it.utils.export.PublicTemplateSevice
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.atlassian.jira.component.ComponentAccessor
@WithPlugin("com.intenso.jira.issue-templates")
def publicTemplateSevice = ComponentAccessor.getOSGiComponentInstanceOfType(PublicTemplateSevice.class)
def templateIdByKey = publicTemplateSevice.getAppliedTemplateIdByIssueKey("IT-100");
def templateIdById = publicTemplateSevice.getAppliedTemplateIdByIssueId(10100L);
Below version 6.4.2
import pl.intenso.it.utils.export.AppliedTemplateSevice
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.atlassian.jira.component.ComponentAccessor
@WithPlugin("com.intenso.jira.issue-templates")
def appliedTemplateSevice = ComponentAccessor.getOSGiComponentInstanceOfType(AppliedTemplateSevice.class)
def templateIdByKey = appliedTemplateSevice.getAppliedTemplateIdByIssueKey("IT-100");
def templateIdById = appliedTemplateSevice.getAppliedTemplateIdByIssueId(10100L);
import pl.intenso.it.utils.export.PublicTemplateSevice
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue;
@WithPlugin("com.intenso.jira.issue-templates")
def publicTemplateSevice = ComponentAccessor.getOSGiComponentInstanceOfType(PublicTemplateSevice.class)
MutableIssue issue = issue
publicTemplateSevice.applyTemplateToIssue("TEMP-4", issue);
import pl.intenso.it.utils.export.PublicTemplateSevice
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue;
@WithPlugin("com.intenso.jira.issue-templates")
def publicTemplateSevice = ComponentAccessor.getOSGiComponentInstanceOfType(PublicTemplateSevice.class)
MutableIssue issue = issue
publicTemplateSevice.copySubtasksFromTemplate("TEMP-4", issue, "", null); //Template, current issue, stages and extra due date value
If you can’t find the answer you need in our documentation, raise a support request.