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

This widget could not be displayed.
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?

This widget could not be displayed.

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 widget could not be displayed.

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

This widget could not be displayed.
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)

This widget could not be displayed.

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

This widget could not be displayed.

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

This widget could not be displayed.

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.

This widget could not be displayed.

Oh! I'll remove it and see laugh

This widget could not be displayed.

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

This widget could not be displayed.

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 ?

This widget could not be displayed.

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. 

This widget could not be displayed.

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.

This widget could not be displayed.

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

This widget could not be displayed.

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.

 

This widget could not be displayed.

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
}
This widget could not be displayed.

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]

This widget could not be displayed.

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
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted yesterday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

52 views 1 0
Join discussion

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