Help with a groovy script.

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

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/

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

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

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

 

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

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

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" )

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 Behnke Community Champion Apr 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")

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 Behnke Community Champion Apr 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"

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

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. 

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

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

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

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Fadoua M. Boualem
Published Monday in Trello

Using Trello to manage events

As a Jira power user, I was at first doubtful that Trello could benefit my workflow. Jira already uses boards (ones you can customize!), so why would I even need to use Trello?! In this post you will...

464 views 7 8
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you