I am creating a mutable issue 'newSubTask' in my groovy script and also setting it's properties, and this is a subtask of the issue on whose On Create transition I am writing this post function. I was using ScriptRunner 4.3.13 up until now, and recently used the SR version 3.0.16 with another JIRA instance and copied this project and ran it and rceived this error of Propertyu not found. Is it due to the older version of script runner? Or is it because I might have made an error in copying? I think it is the former, though. How do I eliminate this error? (Since this JIRA instance has a lot of other projects which are using SR older version, I wouldn't want to upgrade SR and cause a havoc).
Hi Shagufta,
cool. So it is
newSubTask.setAssigneeId(user.key) //or newSubTask.setAssignee(user.directoryUser)
regards, Thanos
Yes this works. I'll modify my script to the older functions. Thanks a lot!!! One last thing, to assign the iissue to the current user, the line
newSubTask.setAssigneeId(user.name)
Will this remain the same? Or is the setAssigneeId function expecting something else in the older versions?
@Thanos Batagiannis [Adaptavist]
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I use JIRA 6.4.7 and SR 3.1.3. For me following function works:
ApplicationUser loggedInApplicationUser = ComponentAccessor.getJiraAuthenticationContext().getUser() IssueInputParameters issueInputParametersCreate = ComponentAccessor.issueService.newIssueInputParameters() issueInputParametersCreate.setSkipScreenCheck(true) issueInputParametersCreate.setIssueTypeId(ComponentAccessor.issueTypeSchemeManager.getSubTaskIssueTypesForProject(taskIssue.projectObject).find{it.name=="Atomic SubTask"}.id) issueInputParametersCreate.setProjectId(taskIssue.projectId) issueInputParametersCreate.setSummary(devSummary.concat(taskIssue.summary)) issueInputParametersCreate.setReporterId(taskIssue.reporterId) IssueService.CreateValidationResult createValidationResult createValidationResult = ComponentAccessor.issueService.validateSubTaskCreate(loggedInApplicationUser, taskIssue.id, issueInputParametersCreate) if (createValidationResult.isValid()) { IssueService.IssueResult createResult = ComponentAccessor.issueService.create(loggedInApplicationUser, createValidationResult) if (createResult.isValid()) { if (log.isDebugEnabled()) log.debug logPref + "New issue: " + createResult.issue ComponentAccessor.subTaskManager.createSubTaskIssueLink(taskIssue, createResult.issue, loggedInApplicationUser.directoryUser) } else { log.error "Error creating new Task Planning issue" for (String error : createResult.getErrorCollection().getErrors().values()) log.error error } } else { log.error "Error validating new Task Planning issue " for (String error : createValidationResult.getErrorCollection().getErrors().values()) log.error error }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am using the similar script suggested by you and I am trying to display error message on UI. But it is showing the error message twice
if (createValidationResult.isValid())
{
log.error("entrou no createValidationResult")
IssueService.IssueResult createResult = issueService.create(currentUser, createValidationResult)
if (!createResult.isValid())
{
log.error(createResult.getErrorCollection().getErrors())
log.error("Error while creating the issue.")
def errorCollection=createResult.getErrorCollection().getErrors().values();
for (String error: errorCollection){
log.debug("inside error collection" +createResult.getErrorCollection().getErrors().get(0))
UserMessageUtil.error("Error : "+error)
}
}
}
I see that loop is being is run only once. Am i doing it in the right way?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I just tested with a SR v3.1.4 the script below
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.Issue import com.atlassian.jira.issue.MutableIssue Issue parentIssue = issue if (parentIssue.isSubTask()) return def user = ComponentAccessor.getJiraAuthenticationContext().getUser() def summariesList = ["summary1", "summary2", "summary3", "summary4", "summary5", "summary6"] def issueFactory = ComponentAccessor.getIssueFactory() def subTaskManager = ComponentAccessor.getSubTaskManager() def constantManager = ComponentAccessor.getConstantsManager() def issueManager = ComponentAccessor.getIssueManager() summariesList.each { subTaskSummary -> MutableIssue newSubTask = issueFactory.getIssue() newSubTask.setSummary(subTaskSummary) newSubTask.setParentObject(parentIssue) newSubTask.setProjectObject(parentIssue.getProjectObject()) newSubTask.setIssueTypeId(constantManager.getAllIssueTypeObjects().find{ it.getName() == "Sub-task" }.id) // Add any other fields you want for the newly created sub task Map<String,Object> newIssueParams = ["issue" : newSubTask] as Map<String,Object> issueManager.createIssueObject(user.directoryUser, newIssueParams) subTaskManager.createSubTaskIssueLink(parentIssue, newSubTask, user.directoryUser) }
PS. You can find your JIRA logs - application server logs.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It is after the step.
Also, there are no errors. I think in the older version of scriptrunner there isn't any way to view errors. Anyway the issue is created without any errors , but the issues i create programmatically in its postfunction aren't created.
So, you are saying, there's no difference in the syntax, and the problem is somethinf else ? okay, i'll check...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I think the reason is in the order of your post functions. You post function should be after the "Creates the issue originally." step.
I suspect the answer will be in your logs. Feel free to paste here any errors you get in your logs.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
No. i create an issue by the normal procedure. and in the postfunction i create subtasks and issues automatically as in the code i have written above. but in this version of scriptrunner i am not being able to create those subtasks or issues through the same script. I click on create, fill the fields on create screen and press create. The issue is created. But the issues and subtasks which were supposed to be created automatically through the postfunction, are not created at all. so i am wondering if the syntax for creating subtasks programmatically in a groovy script was different for older versions.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Cool.
So what you use is to create subtasks and if I understand right is working fine. And your question is how to create an issue (other than a subtask) for a JIRA v.6.* right ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It worked!! Thanks! But the subtasks/other issues are not getting created. I mean, this issue is getting created but not any other issue programmatically. Is there some other syntax for creating issues in older versions? @Thanos Batagiannis [Adaptavist]?
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.
I afraid you have to remove it completely, even commented it will cause issues.
Alternatively, to the workaround described in the linked bug above, you can also run the script from a file.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
That line is commented in my code . So it isn't executing, hence doesnt make any difference, right? @Thanos Batagiannis [Adaptavist]
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Shagufta,
Do you have anywhere in your script something like
log.info "Issue with summary ${newSubTask.summary} created"
There was a bug SRJIRA-544 which was fixed for the latest versions. If you cannot upgrade then a workaround is described in the issue above.
regards, Thanos
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am not sure, but trouble could be here:
subTaskManager.createSubTaskIssueLink(parentIssue, newSubTask, user)
Try to replace newSubtasc with value returned by issueManager.createIssueObject(user, newIssueParams)
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.
This simple code works for JIRA 7.1.0 and ScriptRunner 4.3.13 . But now it is giving this error on the create issue screen itself, in the other version. (JIRA 6.4, SR 3.0.16) @Vasiliy Zverev
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
the JIRA version there is 6.4 and ScripRunner is 3.0.16.
The code is as follows:
if (valueOfRType == 'someVal') { MutableIssue newSubTask = issueFactory.getIssue() newSubTask.setAssigneeId(user.name) newSubTask.setSummary('ABC') newSubTask.description="XYZ" newSubTask.setParentObject(parentIssue) newSubTask.setFixVersions(Arrays.asList(versionn))newSubTask.setProjectObject(parentIssue.getProjectObject()) newSubTask.setIssueTypeId(constantManager.getAllIssueTypeObjects().find{it.getName() == "Sub-task"}.id) Map<String,Object> newIssueParams = ["issue" : newSubTask] as Map<String,Object> issueManager.createIssueObject(user, newIssueParams) subTaskManager.createSubTaskIssueLink(parentIssue, newSubTask, user) .. ..
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Dear Shagufta, ff you use script on different JIRA instances it mean that JIRA version also changed. Also changed version of JIRA API.
Could you provide code and JIRA versions for both instances?
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.