Help with a groovy script.

Gaven Ray April 15, 2016

I am trying to translate the following in to a Groovy script and I am a complete noob when it comes to scripting. I can read a script and figure out for the most part what it should do but writing one is a completely different thing.

If Platform Engineering Team = Platform EU

I am trying to use this to assign a ticket to a role on create if the custom field (Platform Engineering Team) has value (Platform EU) set. 

Please help me out.

4 answers

1 accepted

1 vote
Answer accepted
JamieA
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.
April 17, 2016

Assuming this field is a select list, you could use:

if (cfValues['My Single Select']?.value == "Some value")

or do it the long-hand way, there are lots of examples of that here and in the docs: https://scriptrunner.adaptavist.com/latest/jira/

Gaven Ray April 18, 2016

When I tried this:

IF (cfValues['Platform Engineering Team']?.value == "Platform EU")

I got the following error:

Error creating issue: No such property: cfValues for class: Script1

JamieA
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.
April 18, 2016

can you provide a screenshot of the configuration so we can check the context

Gaven Ray April 18, 2016

Screen Shot 2016-04-18 at 9.42.36 AM.png

 

Here is where I am trying to put this in to place. 

JamieA
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.
April 18, 2016

that's not ScriptRunner, it's JIRA misc workflow extensions IIRC.

Steve Behnke [DiscoverEquip.com]
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.
April 18, 2016

laugh Always a fun day here on Atlassian Answers.

Daniel, the docs are listed here – https://innovalog.atlassian.net/wiki/display/JMWE/Post-functions. In this case, something like this should be close – 

if ( issue.get("customfield_12345")?.value == "Platform EU" )
Gaven Ray April 18, 2016

New error on ticket creation with that in place.

Error creating issue: startup failed: Script1.groovy: 1: unexpected token: @ line 1, column 62. 01")?.value == "Platform EU" ) ^ 1 error 

I found two old questions that seem to have a similar error.

Question 1

Question 2

I took out the extra spaces in the script above from @Steve Behnke [DiscoverEquip.com] and the error just changed the column number to 60. 

Thanks for the help and at least getting me to this point.

Steven F Behnke
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.
April 18, 2016

All the whitespace seems to be garbage, I am not sure why. The script condition I wrote has exactly 57 characters in it, so be sure to get all the whitespace out. I cleaned it up here, but I still haven't had time to test this further, sorry – 

if(issue.get("customfield_12345")?.value=="Platform EU")
Gaven Ray April 19, 2016

With no spaces what so ever I get the same error with the number being 57. Just to confirm that the plug in was working and it was just an issue with the Groovy in the field I removed the check from " Only if condition is true "  and it did as it should.  I need the Groovy to work or there is no sense in having the auto-assign option because it will be sending it to the Platform EU team. 

Steven F Behnke
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.
April 19, 2016

Perhaps dump the if statement. It's been forever since I wrote conditions for MWE so pardon me...

issue.get("customfield_12345")?.value=="Platform EU"
Gaven Ray April 19, 2016

Hey @Steve Behnke [DiscoverEquip.com],

You have been great. I removed the IF and now it is not throwing an error. It is not assigning it but that is not a fault of the script as much as the plugin. Now to figure out why that might be. I have checked roles and permissions for the project I am testing on which matches the project this is ultimately going in to.

Thanks

Daniel

Steve Behnke [DiscoverEquip.com]
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.
April 19, 2016

So, we don't need to construct an if statement to pass a true/false, we just need to place the condition itself. Of course. smile 

No problem at all Daniel, I enjoy helping. 

0 votes
Steve Behnke [DiscoverEquip.com]
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.
April 18, 2016

And your script is a post-function? Or is this for the Script Console?

0 votes
Gaven Ray April 18, 2016

Platform Engineering Team is a custom field (single select) and Platform EU is one of it's options. 

0 votes
Steve Behnke [DiscoverEquip.com]
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.
April 17, 2016

What is the context of this script? What is 'Platform Engineering Team,' what is 'Platform EU?'

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events