Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Automatic create issue after we update field

Anonymous March 2, 2022

I have one story inside that has a custom field (database picker) called "Input" that is a dropdown with the value options being  A, B, C.... N. When a customer is updating an issue(story) and they choose their "Input" and save the issue, I would like it to automatically create a particular bug for a particular "Input"(A, B, C, etc) he selected from "Input".

For example, when a customer chooses "A", "B", "H" and save the story.  I would like it to automatically create 3 new bugs, reflecting their name A, B, and H.

Is this achievable with ScriptRunner?

1 answer

1 accepted

0 votes
Answer accepted
Sachin Dhamale
Community Champion
March 2, 2022

@Anonymous ,

 

Yes Its Possible. You need to write script listener for this.

When issue will be created on that script listener will run.

In that listener you want to read "input" custom field and in the for loop you need to write logic to create the bug with summary of value of that custom field.

 

groovy Code to create issue You can use this on postfunction or listener 

 

import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueInputParameters
import com.atlassian.jira.user.ApplicationUser

IssueService issueService = ComponentAccessor.getIssueService()
IssueInputParameters issueInputParameters = issueService.newIssueInputParameters();
def issueTypeID = "10103" // Give the id of bug

def customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_10259");// here replace the ID with ID of your input custom field.
List<stirng> value = (String)issue.getCustomFieldValue(customField); // This will return the of list of value

value.each{ val ->

issueInputParameters
.setProjectId(1000) //mention project if
.setSummary(val) // value of custom field
.setDescription("test desc")
.setIssueTypeId(issueTypeID)
.setPriorityId(1)
.setReporterId(2)
.setAssigneeId(2) // mentione more field as per requirment

log.error("Summary: " + issueInputParameters.getSummary())

ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

IssueService.CreateValidationResult createValidationResult =
issueService.validateCreate(user, issueInputParameters)

if (createValidationResult.isValid())
{
log.error("entrou no createValidationResult")
IssueService.IssueResult createResult = issueService.create(
user, createValidationResult)
if (!createResult.isValid())
{
log.error("Error while creating the issue.")
}
}

}
Anonymous March 2, 2022

Hi @Sachin Dhamale 

Thank you,

FYI: When an issue will be created on that script listener will run.>>> I'm updating the issue.

 

And I do not have scripting knowledge, please help me.

Sachin Dhamale
Community Champion
March 2, 2022

@Anonymous ,

I have send you the sample logical code. make the syntactical changes if needed. Also check on script runner site it will help you to write code.

Accept the answer if it helps

Anonymous March 2, 2022

.

Suggest an answer

Log in or Sign up to answer