How can I access the value of a field in the transition screen of a post function?

MattS
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.
August 24, 2016

I'm using the Clone and Link ScriptRunner post function. I want to take a value from a Select field on the transition's screen and use that value to set a different field in the newly created issue.

However, the select field value in the transition screen gets saved into the parent issue during the transition (as expected). Then the next time I execute the transition the value of the Select field is taken from the parent issue, not from any updated value on the transition screen.

My question is how can I access the value of a field in the transition screen of a post function? The value of the field may not be the same as the value in the parent issue

 

2 answers

1 accepted

1 vote
Answer accepted
Jonny Carter
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.
August 25, 2016

The order of operations with the Clone and link postfunction may take some explaining.

In the binding of the Additional Actions script, you'll have two objects:

  • issue - represents the clone
  • sourceIssue - represents the issue that you executed the workflow on

The issue gets created before any of the fields set during the workflow transition screen are updated. So, issue will have a copy of all of sourceIssue's fields at the time the transition was initiated.

However, sourceIssue will have the updated field values. As such, you can use that to update the customFields on the issue object. For example:

import com.atlassian.jira.component.ComponentAccessor

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def field = customFieldManager.getCustomFieldObjectByName("my custom field")

def cloneCurrentValue = issue.getCustomFieldValue(field)
log.debug("Value on cloned issue: $cloneCurrentValue")
def parentIssueNewValue = sourceIssue.getCustomFieldValue(field)
log.debug("Value on parent issue: $parentIssueNewValue")
 
//Now set the value on the target issue
issue.setCustomFieldValue(field, parentIssueNewValue)

transientVars does have some of the values from the workflow screen, including the comment that was entered. Depending on what you're trying to get at, it may be more expedient.

MattS
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.
September 1, 2016

You're right, that is quite hard to explain. I don't think I can read a value from the transition screen and update both parent and clone though

Jonny Carter
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.
September 7, 2016

I don't quite see why not. Are you saying that the value entered on the workflow screen isn't available on either the sourceIssue object or the transientVars?

Brian W. Bishop November 7, 2016

are the transientVars accessible from the REST API (or other mechanism) when one is using the JIRA Cloud product?

1 vote
MattS
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.
August 25, 2016

What I ended up doing was not using a field on the transition screen. I just added a condition to the transition that needs the Select field to be set in the issue. Still, I'd like to understand how ScriptRunner post functions let you access the original issue, the transition screen fields and the cloned issue. I see transientVars['originalissue'] is an IssueImpl object

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events