Forums

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

Approval Does Not Approve

Paul Tiseo
Contributor
April 8, 2019

I have a simple workflow with three serial approval nodes.

The first node is setup to approve on the basis of the users in the Approval field and the field is set as a default value from the Service Desk request type. This user gets the approve/deny email.

Whether or not the trigger is from the email or from inside Jira itself, the approval transition is not followed. I do have a ScriptRunner post-function that resets the Approver field. The post-function does indicate that it is triggered, but somehow I am not ending up at the next status.

Here's the script: (<uesrname> hidden)

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser

ApplicationUser approver = ComponentAccessor.getUserManager().getUserByKey("<username>")

issue.setCustomFieldValue(ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Approvers"), approver)

Any suggestions?

2019-04-08 16_24_00-Edit — U2C Vehicle Approval Workflow - JTA Projects.png

2 answers

1 accepted

0 votes
Answer accepted
Paul Tiseo
Contributor
April 9, 2019

The problem was a silly mistake. The Approver field requires an array or collection as the second parameter to setCustomFieldValue(), not a single ApplicationUser object.

New script is:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.user.ApplicationUser

ApplicationUser approver = ComponentAccessor.getUserManager().getUserByKey('<username>')
//log.error 'approver: ' + approver

def customFieldCollection = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectsByName('Approvers')
CustomField field = customFieldCollection.find {it.getFieldName() == 'Approvers'}
//log.error 'field: ' + field

try {
issue.setCustomFieldValue(field, [approver])
}
catch (Exception ex) {
log.error ex.getMessage()
}

//log.error 'end'

0 votes
Tom Lister
Community Champion
April 8, 2019

Hi @Paul Tiseo 

your transition is probably throwing an error. Can you access the jira logs?

I would also recommend adding some log statements and/or checks on values returned by your api calls to check they are working as you expect.

Suggest an answer

Log in or Sign up to answer