Forums

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

Groovy Script for creating issue based on given custom field condition

DILEEP KUMAR April 12, 2018

Hi All, 

I have written the below script for creating the issue in Jira, but getting issue created.

import com.atlassian.jira.bc.issue.IssueService.CreateValidationResult
import com.atlassian.jira.bc.issue.IssueService.IssueResult
import com.atlassian.jira.issue.IssueManager
import org.apache.log4j.Category
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.*
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.bc.issue.IssueService;
import com.atlassian.jira.bc.issue.IssueService.CreateValidationResult;
import com.atlassian.jira.bc.issue.IssueService.IssueResult;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;

Collection<CustomField> customFields = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectsByName("customFieldId=18229");
println(customFields);

for (CustomField customField : customFields) {
if (customField.getValue(issue).toString().equals("Yes")) {

//customField=Yes, create issue
IssueService issueService = ComponentAccessor.getIssueService();
println(issueService);
CreateValidationResult createValidationResult = issueService.validateCreate(currentUser, issueInputParameters);
println(issueService);
if (createValidationResult.isValid())
{
IssueResult createResult = issueService.create(currentUser, createValidationResult);
if (!createResult.isValid())
{
println("issue created");
}
}
}
}

 

Any help/Suggestion would be appreciated.

Regards,

Dileep Kumar

1 answer

0 votes
Tarun Sapra
Community Champion
April 12, 2018

Why are you creating a script for it? what's your use-case as it's generally supported by script runner to create an issue at workflow post-function.

DILEEP KUMAR April 12, 2018

Hi Tarun,

Thanks for the help !!

I want the script which will create the issue/sub-task based on given Custom Field.

Suppose if CodeReview(Custom Field) is yes then issue/sub-task should be created.

After this created issue, i want it to link with another issue.

This is my overall requirement.

Can you please help me with the groovy script for above requirement ?

 

Regards,

Dileep Kumar

Tarun Sapra
Community Champion
April 12, 2018

If you have script runner plugin then it's a built-in post function to create a sub-task or to create an issue. You don't have to write  a script for it.

Tarun Sapra
Community Champion
April 12, 2018

And you can easily add a condition before the execution of the post-function, and if the condition is true only then the post-function will be executed.

DILEEP KUMAR April 12, 2018

Hi Tarun,

Thanks for the help !!

I will check it, if any issue will let you know.

Regards,

Dileep Kumar

DILEEP KUMAR April 13, 2018

Hi Tarun,

Yes, you are right. The feature is available, but i need to automate this feature by using custom script. So i want the groovy script.

If you can help, it would be great !!

 

Regards,

Dileep Kumar

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events