I am trying to write a Groovy Expression for Set Field Value to constant or Groovy expression Function. I want it to change a group lookup custom field value based on what exists in another custom field. I cannot seem to get it to work correctly. I think it is my syntax that is off.
Here is what I have currently:
if(issue.get("customfield_18173") == "Desktop" || issue.get("customfield_18173" == "Support" || issue.get("customfield_18593") == "Desktop" || issue.get("customfield_18593") == "Support"){ setCustomFieldValue("customfield_18594", "Help Desk"); }
It all depends on where you are trying to use your Groovy expression. If it's during a transition, you should use the Set Field Value to Constant or Groovy Expression post-function, with "Help Desk" as the value (text) and just the test as the conditional Groovy expression:
issue.get("customfield_18173") == "Desktop" || issue.get("customfield_18173" == "Support" || issue.get("customfield_18593") == "Desktop" || issue.get("customfield_18593") == "Support"
Well that's what I had initially and it worked, however, I will be doing this for over 50 different constant values and I was hoping I could do it all in one post function instead of 50 different ones. What is the point of the Groovy Expression option in place of a raw value?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
In the Groovy expression of the Set Field Value post-function, you can put some complex logic (like a cascade of ifs, or switch statements). The limitation is that if you want to not change the field value under some condition, you'll actually need to return... the current value of the field (using issue.get of course).
So, you can do something like:
if(issue.get("customfield_18173") == "Desktop" || issue.get("customfield_18173" == "Support" || issue.get("customfield_18593") == "Desktop" || issue.get("customfield_18593") == "Support") return "Help Desk"; if ([...]) return "something else"; [...] return "otherwise";
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Oh wow, I guess I was just making it way more complicated than it needed to be. I will give this a shot.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This works! Thank you very much!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
So I had this on a random transition to test and it works, but I want to have this be on creation. When I try to do the same exact thing on the create transition it does not work. Any idea what I am doing wrong?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You have to put the post-function at the end of the list of post-functions in case of create transitions.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Your syntax is incorrect, you have to use customFieldManager and issuse.getCustomFieldValue() method.
Please see here - https://answers.atlassian.com/questions/188266
And once you have the value you just need to update the value based on if condition just like - https://answers.atlassian.com/questions/211505
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
And this works within the groovy expression box on post function?
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.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.