I have a groovy script and in it I create issues several times under different conditions. I have copied pasted the below code several times in my script. I want to write a function to do that. But when i write these lines in a function, nothing is accessible. The issueFactory, the functions of MutableIssue, nothing. They give an error. Why is that?!
MutableIssue newSubTask = issueFactory.getIssue() newSubTask.setAssigneeId(user.name) newSubTask.setParentObject(parentIssue) newSubTask.setFixVersions(Arrays.asList(versionn)) newSubTask.setProjectObject(parentIssue.getProjectObject()) newSubTask.setIssueTypeId(constantManager.getAllIssueTypeObjects().find{it.getName() == "Sub-task"}.id) ... ..
Hi Shagufta,
The following code will create a issue in the project TP of type task:
def projectKey = 'TP' def taskType = get('/rest/api/2/issuetype').asObject(List).body.find { it['name'] == 'Task' }['id'] post('/rest/api/2/issue') .header('Content-Type', 'application/json') .body( [ fields: [ summary : 'Task Summary', description: "Don't forget to do this!.", project : [ key: projectKey ], issuetype : [ id: taskType ] ] ]) .asString().body
This page details the differences between ScriptRunner Server and Cloud: http://scriptrunner-docs.connect.adaptavist.com/jiracloud/migrating.html
Regards, Jon
I know and i have done all of it already. I am just wondering if it is possible to put it in a user defined method, to enhance code reusability
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
As you are using JIRA Cloud, there are some differences in the usage. You will have to use JIRA's REST API to create new issue. Please have a look at the differences in Script Runner for JIRA Cloud documentation on the differences between Server and Cloud and JIRA REST API how to create an issue. In case it is suitable for your use case you can use Workflow Post function to create subtask described here.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Are you using JIRA Cloud or JIRA Server?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Here is code example for subtask creation. Here created a cubtask for each user into multyuser select field:
import com.atlassian.jira.component.ComponentAccessor; import com.atlassian.jira.bc.issue.IssueService import com.atlassian.jira.issue.Issue; import com.atlassian.jira.issue.IssueInputParameters; import com.atlassian.jira.issue.index.IssueIndexManager; import com.atlassian.jira.config.SubTaskManager; import java.text.SimpleDateFormat; import java.text.FieldPosition; import java.sql.Timestamp; //Issue issue = ComponentAccessor.getIssueManager().getIssueObject("OEBSR12-3631") if(issue.getDueDate() == null){ Calendar dueDate = Calendar.getInstance(); int addedDays = 0; while(addedDays < 2 ){ dueDate.add(Calendar.DAY_OF_YEAR, 1) if( !((dueDate.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY) || (dueDate.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY)) ){ ++addedDays; } } issue.setDueDate(new Timestamp(dueDate.getTimeInMillis())) } IssueService issueService = ComponentAccessor.getIssueService(); IssueService.IssueResult issueResult; IssueService.CreateValidationResult createValidationResult; IssueInputParameters issueInputParameters = issueService.newIssueInputParameters(); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd/MM/yy"); issueInputParameters.setDueDate(simpleDateFormat.format(new Date( issue.getDueDate().getTime()), new StringBuffer(), new FieldPosition(0)).toString()); issueInputParameters.setIssueTypeId("11104") issueInputParameters.setProjectId(issue.getProjectId()) issueInputParameters.setSummary("Согласование документа") issueInputParameters.setDescription(issue.getDescription()); curUser = ComponentAccessor.getJiraAuthenticationContext().getUser(); SubTaskManager subTaskManager = ComponentAccessor.getSubTaskManager(); IssueIndexManager issueIndexManager = ComponentAccessor.getIssueIndexManager(); long soglasovantId = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Согласовант").getIdAsLong(); for(user in ComponentAccessor.getCustomFieldManager().getCustomFieldObject(14600L).getValue(issue)){ issueInputParameters.setAssigneeId( user.name); issueInputParameters.addCustomFieldValue(soglasovantId, user.name) createValidationResult = issueService.validateSubTaskCreate(curUser, issue.getId(), issueInputParameters); if(createValidationResult.isValid()){ issueResult = issueService.create(curUser, createValidationResult); //return "" + issueResult.getErrorCollection(); subTaskManager.createSubTaskIssueLink(issue, issueResult.getIssue(), user.directoryUser); issueIndexManager.reIndex(issue); issueIndexManager.reIndex(issueResult.getIssue()); } }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Given that this is ScriptRunner for JIRA Cloud the above code will not work
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.