Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Error in the Custom script post-function

Marat May 29, 2019

Hi

I have a few error in the Custom script post-function

can you help me?

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue

def constantManager = ComponentAccessor.getConstantsManager()
def issueManager = ComponentAccessor.getIssueManager()
def issueFactory = ComponentAccessor.getIssueFactory()
def subTaskManager = ComponentAccessor.getSubTaskManager()

def personFieldsIds = [14098,14099]

for (int personFieldsId:personFieldsIds){
def person = customFieldManager.getCustomFieldObject(personFieldsId)
def personValue = issue.getCustomFieldValue(person)
if (personValue){
MutableIssue newSubTask = issueFactory.getIssue()
newSubTask.setReporter(issue.reporter)
newSubTask.setAssignee(personValue?.getKey())
newSubTask.setSummary("Subtask for " + personValue?.getDisplayName())
newSubTask.setParentObject(issue)
newSubTask.setProjectObject(issue.getProjectObject())
newSubTask.setIssueTypeId(constantManager.getAllIssueTypeObjects().find{it.getName() == "Sub-task"}.id)
newSubTask.setDescription("Description for " + personValue?.getDisplayName())
Map<String,Object> newIssueParams = ["issue" : newSubTask] as Map<String,Object>
issueManager.createIssueObject(issue.reporter, newIssueParams)
subTaskManager.createSubTaskIssueLink(issue, newSubTask, issue.reporter)
}
}

func.PNG

 4.PNG3.PNG2.PNG

Jira v 6.3.10

2 answers

0 votes
Payne
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 29, 2019

You're not defining customFieldManager before using it. You need a line like

def customFieldManager = ComponentAccessor.getCustomFieldManager()

Marat May 29, 2019

That didn't help either

Payne
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 30, 2019

It may not completely solve your problem, but it is certainly one error. Nic noted another error about your array of IDs.

0 votes
Nic Brough -Adaptavist-
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 29, 2019

Line 12 does not work because you're passing an array of numbers into a function that is expecting a single ID.  This chains down into all of the other errors, so fix that (by using a single field to read, rather than two), and it should be ok.

Marat May 29, 2019

the error remained

5.PNG

Marat May 30, 2019

@Nic Brough -Adaptavist- Tell me pls, what's the problem?

Nic Brough -Adaptavist-
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 30, 2019

Again, you are passing the wrong thing into the getCustomFieldObject call - it needs a single field reference, not a string that looks like the display of an array with two field ids in it.

Suggest an answer

Log in or Sign up to answer