Forums

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

How create an issue via groovy filling a cascading field?

Rafael Costa
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.
March 9, 2022

The code that I trying run is it:

...
def issueInputParameters = issueService.newIssueInputParameters().with {
    setProjectId(project.id)
    setIssueTypeId(issueType.id)
    setReporterId(loggedInUser.name)
    setSummary(summary)
    setPriorityId(priorityId)
    setComponentIds(component as Long)
    setDescription(description)
    addCustomFieldValue(data_field_id, data as String)
    addCustomFieldValue(area_solicitante_field_id, "Department -> IT")
  }


def validationResult = issueService.validateCreate(loggedInUser, issueInputParameters)
if (validationResult.isValid()){
    def result = issueService.create(loggedInUser, validationResult)
}else{
    return validationResult.getErrorCollection()    
}

 

But I give this error:

Errors: {customfield_17401=The option 'Department -> IT' is an invalid parent option}
Error Messages: []

 

How parse data correctly to fill this error?

3 answers

0 votes
Sergiienko Volodymyr December 15, 2022

Hi! 
For searchers like me )
To set 2nd level add ":1" to custom field Id:

def cf = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectsByName("Your Cascade field name")[0]

def issueInputParameters = issueService.newIssueInputParameters().with {

...

    addCustomFieldValue(cf.getId(), 'Parent value text or Id number')

    addCustomFieldValue(cf.getId() + ":1", 'Child value text or Id number')

}
0 votes
Carlos Tichy
Contributor
May 14, 2022

Hi @Rafael Costa! Create first the issue with the parent field. (Also I mean don't put the child field in the creation process). After having the issue created, then update the issue, filling the child field.

Good luck!

Carlos Tichy
Contributor
May 15, 2022

Hi @Rafael Costa
look at the following script excerpt, precisely that is what I say, you can create first the Issue, and after that (probably based on your conditions - selecting the child field) update then the Issue; in my case, I'm assigning it after creation (I could have done the creation with the assignment at once, but I needed to do it in two steps.):


    
    def issueInputParameters = issueService.newIssueInputParameters().with {

        setProjectId(project.id)

        setIssueTypeId(issueType.id)

        setReporterId(reporter.toString())

        setSummary(summary)

        setDescription(description)

        setPriorityId(priorityId)

        addCustomFieldValue("customfield_16873", objectData.objectKey as String)

    }

   

   

    def validationResult = issueService.validateCreate(loggedInUser, issueInputParameters)

    assert validationResult.valid : validationResult.errorCollection

   

    def result = issueService.create(loggedInUser, validationResult)

    assert result.valid : result.errorCollection

   

    def String issueKey = result.getIssue().getKey()

    def issue = issueManager.getIssueObject(issueKey)

    def userAssignee = userManager.getUserByKey(assignee.toString())

    def validateAssignResult = issueService.validateAssign(userAssignee, issue.id, issue.reporterId)

    assert validationResult.valid : validateAssignResult.errorCollection

    def resultAssign = issueService.assign(userAssignee, validateAssignResult)

    assert resultAssign.valid : validateAssignResult.errorCollection
0 votes
Mohamed Benziane
Community Champion
March 9, 2022
Rafael Costa
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.
March 10, 2022

The context is different, this link show how set a cascading field, but I need create an issue with the field filled.

The problem was in the child option. I could create an issue with parent option only and child as null, so I create the issue, retrieve it, then set the child option.

it was not as presented on the link, but help me to create my own script, thanks!

Suggest an answer

Log in or Sign up to answer