Error creating issue: Property 'newSubTask' not found?

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).

17 answers

0 vote
Vasiliy Zverev Community Champion Dec 06, 2016

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?

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)    
 
..
..

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

0 vote
Vasiliy Zverev Community Champion Dec 06, 2016

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)

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

That line is commented in my code . So it isn't executing, hence doesnt make any difference, right? @Thanos Batagiannis [Adaptavist]

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.

Oh! I'll remove it and see laugh

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]?

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 ?

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. 

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.

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...

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.

 

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
}

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]

Hi Shagufta,

cool. So it is 

newSubTask.setAssigneeId(user.key) 
//or
newSubTask.setAssignee(user.directoryUser)

regards, Thanos   

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Thursday in Jira

Mission-critical battery manufacturer fulfills FAA software requirements with Commit Policy Plugin

EaglePicher Technologies is a leading manufacturer of battery systems for diverse industries like defense, aviation, space or medical. As they operate in highly regulated industries, keeping a clear ...

180 views 0 2
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you