Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,365,058
Community Members
 
Community Events
168
Community Groups

Error when i created sub-task

Guys, pls help. I have error when i try create sub issue.  My code 

 

 ApplicationUser jiraBotUser = ComponentAccessor.getUserManager().getUserByName("JiraBot")
def issueInputParameters = issueService.newIssueInputParameters().with {
        setProjectId(issue.projectId)
        setIssueTypeId(TYPE_SUB_TASK_ID)
        setReporterId(issue.reporter.displayName)
        setSummary("Clone ${issue.summary}")
        addCustomFieldValue((Long) SP_FIELD_ID, storyPoints)
    }
ef createValidationResult = issueService.validateSubTaskCreate(reporter, issue.id, issueInputParameters)
    if (createValidationResult.isValid()) {
        def issueResult = issueService.create(reporter, createValidationResult)
        def subtask = issueResult.issue}
i have error : 
Anonymous applications do not have permission to create files in this project. Try logging in first
but if i push this scrpit hands, sub-taks create  by me, not jirabot.
what am I doing wrong?  how to create a subtask with a special account for this?

1 answer

0 votes
Alex Koxaras Community Leader Aug 22, 2022

Hi @Руслан 

Who is "jirabot" user, and does he has an account on your instance? If that user is anonymous, then as your log states you have not give proper permissions to that user.

Hi, @Alex Koxaras . Jirabot its tech account, which is made for various things in jira. He has admin access, just like my account. He is also in the project. Maybe it's because he's always offline and logged in at the moment?

Alex Koxaras Community Leader Aug 22, 2022

Can you please tell me a bit more of what you are trying to achieve? You are trying to create a subtask. That's clear. How do you do that? Where do you place and run your code?

@Alex Koxaras its postfunction, then task close, i need create taks copy one field , and close subtask.  

i have 3 block code 

 

ApplicationUser jiraBotUser = ComponentAccessor.getUserManager().getUserByName("JiraBot")

 

first i copy value filed in another field:

 

 IssueInputParameters issueInputParams = issueService.newIssueInputParameters()
    issueInputParams.addCustomFieldValue(COST_FIELD_ID,storyPoints.toString())
    def updateValidationResult = issueService.validateUpdate(jiraBotUser, issue.id, issueInputParams)
    if (updateValidationResult.isValid()) {
       logger.info(updateValidationResult.isValid().toString())
        issueService.update(jiraBotUser, updateValidationResult, EventDispatchOption.DO_NOT_DISPATCH, false)
    } else {
        commentManager.create(issue, jiraBotUser, "error : ${updateValidationResult.errorCollection.toString()}", true)
   
    logger.info(issue.key + ("") + updateValidationResult.errorCollection.toString())
    }

}
second : i want to create sub task: 
def issueInputParameters = issueService.newIssueInputParameters().with {
    setProjectId(issue.projectId)
    setIssueTypeId(TYPE_SUB_TASK_ID)
    setReporterId(issue.reporter.displayName)
    setSummary("Clone ${issue.summary}")
    addCustomFieldValue((Long) SP_FIELD_ID, storyPoints.toString())

}


def createValidationResult = issueService.validateSubTaskCreate(jiraBotUser , issue.id, issueInputParameters)
if (createValidationResult.isValid()) {
    def issueResult = issueService.create(jiraBotUser , createValidationResult)
    def subtask = issueResult.issue
    ComponentAccessor.subTaskManager.createSubTaskIssueLink(issue, subtask, jiraBotUser )

    JiraWorkflow workflow = workflowManager.getWorkflow(subtask)
   
and last :
def transitionValidationResult = issueService.validateTransition(jiraBotUser,subtask.getId(),STATUS_TO_CLOSE_ID,new IssueInputParametersImpl())
    if(transitionValidationResult.isValid()){

        try {
            issueService.transition(jiraBotUser, transitionValidationResult)
        }
        catch(e) {
          logger.info(issue.key + ("") + transitionValidationResult.errorCollection.toString())
            commentManager.create(subtask, jiraBotUser, e.toString(), true)
        }

    }
}
else {
    logger.info(issue.key + ("") + createValidationResult.errorCollection.toString())
    commentManager.create(issue, jiraBotUser, " ERROR :${createValidationResult.errorCollection.toString()}", true)
}

}
When i сall the script with hands, 1 and 3 block work great, but when need create task, task create by me(my account), not jirabot. 
when postfunction called, scrtipt failed in 2 step , error - anonyms user

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events