Are you in the loop? Keep up with the latest by making sure you're subscribed to Community Announcements. Just click Watch and select Articles.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

ScriptRunner Post Function is inconsistent

Edited
Randy
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.
Apr 19, 2018

Hi Folks,

 

This post function seems to be inconsistent for me with the value printed being either pre-screen or post-screen.

 

Any ideas on what could be happening and how i could fix?

 

def someFakeCustomFieldId = 'customfield_123456'

def issueWithScreenChanges = get("/rest/api/2/issue/${issue.id}")
.queryString("fields", someFakeCustomFieldId)
.asObject(Map)
.body

def newValue1 = issueWithScreenChanges.fields[someFakeCustomFieldId] as String

logger.info(newValue1)

def newValue2 = issue.fields[someFakeCustomFieldId] as String

logger.info(newValue2)

2 answers

1 accepted

Suggest an answer

Log in or Sign up to answer
0 votes
Answer accepted
Randy
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.
Jul 18, 2018

Discovered that because saves from a transition are async, the values entered into the screen cannot be reliably retrieved during the post function.  I was able to work around this by converting to a listener.

0 votes
Neta Elyakim
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.
Jul 18, 2018 • edited

Try this :

def issueBody = issueWithScreenChanges.body
return issueBody.fields[someFakeCustomFieldId] as String

Also, in post function you don't need to get the issue, you can do this:

def someFakeCustomFieldId = 'customfield_123456'


def newValue1 = issue.fields[someFakeCustomFieldId] as String

logger.info(newValue1)

def newValue2 = issue.fields[someFakeCustomFieldId] as String

logger.info(newValue2)

If you take the issueWithScreenChanges object you need to add "body", but if you run the script as post function you can just take the cf from the issue object like this- 

issue.fields[someFakeCustomFieldId]

 

Randy
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.
Jul 18, 2018

Thanks Neta.  You'll see that i'm already pulling body as part of issueWithScreenChanges (Line 6 of my example)

 

I went ahead an posted what I discovered and the solution below.

TAGS
AUG Leaders

Atlassian Community Events