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.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
can you provide a screenshot of the configuration so we can check the context
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
that's not ScriptRunner, it's JIRA misc workflow extensions IIRC.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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" )
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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")
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
No problem at all Daniel, I enjoy helping.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
And your script is a post-function? Or is this for the Script Console?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
What is the context of this script? What is 'Platform Engineering Team,' what is 'Platform EU?'
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.