Forums

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

Help creating Scriptrunner Workflow Post Function to assign user to issue

Darron February 17, 2022

Hello -

I have a specific use case I'm trying to use script runner to solve and pinging the community for assistance.

There is a field that is required to be set "Developer Contact" info on creation of the ticket. I would to implement a workflow transition, where if the ticket fails verification, the ticket is assigned to the Developer Contact. 

The solution I thought of was to use scriptrunner workflow post function to run a script during the transition that would make the assignee = to the "Developer Contact" field.

Since this is all happening inside the same issue, I was thinking of using the following:


//get the issue key
def issue = issue.key

// Specify the name of the list field to set
def userPickerFieldName = "Developer Contact"

// Get the Approver Custom field to get the option value from
def customField = get("/rest/api/2/field")
.asObject(List)
.body
.find {
(it as Map).name == userPickerFieldName
} as Map

// Check if the custom field returns a valid field and is not null
assert customField != null : "Cannot find custom field with name of: ${userPickerFieldName}"

// Get the issue object to get the field value from
def result = get('/rest/api/2/issue/' + issue)
.header('Content-Type', 'application/json')
.asObject(Map)

// Get the accountID value from the custom user picker field
def assigneeValue = result.body.fields.(customField.id).accountId

//logger.info('Assignee Value is' + assigneeValue)

def updateResult = put('/rest/api/2/issue/' + issue)
.header('Content-Type', 'application/json')
.body([
fields:[
// Update the assignnee to the value of the custom user picker field. We are using the account ID so that the format is compliant with the upcoming GDPR changes.
assignee:[id:assigneeValue]
]
])
.asString()


 

 

However I receive the following error: 

java.lang.NullPointerException: Cannot get property 'accountId' on null object at Script1.run(Script1.groovy:24) at Script1$run.call(Unknown Source) at Script1$run.call(Unknown Source) at com.adaptavist.sr.cloud.workflow.AbstractScript.evaluate(AbstractScript.groovy:33) at com.adaptavist.sr.cloud.events.ScriptExecution.run(ScriptExecution.groovy:29) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at ConsoleScriptExecution1_groovyProxy.run(Unknown Source)

 

Could someone point me to what is wrong in the code? Also, is there a simpler way of doing this?

1 answer

0 votes
Aditya Sastry
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.
February 17, 2022

Is the verification done during creation of ticket. I believe it is a step after the ticket is created. If you can send a workflow screenshot it will help to understand the ask better.

If verification transition comes after creation then I assume it can be done by simply copying the field values postfunction.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events