Hi
I've been able to grab this example script but am receiving errors so unable to get it working
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
def groupManager = ComponentAccessor.getGroupManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def group = groupManager.getGroup("Automations") // get the CM group
def usersInGroup = groupManager.getUsersInGroup(group) // get the users in that group
def fieldToSet = CustomFieldManager.getCustomFieldObjectsByName("Approvers.") // get the CM Approvers custom field
fieldToSet.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(fieldToSet), usersInGroup), new DefaultIssueChangeHolder()) // update CM Approvers with users
I've receiving these errors:
Unfortunately having to do this because Atlassian still hasn't added support for security groups for Approvals
You are calling CustomFieldManager instead of customFieldManager.
Also, is your custom field is "Approvers." (with a full stop) or "Approvers"?
Yeh it is the one with the full stop, someone before my time created a custom field for approvers instead of using the native one and we already have a screen set up on that one so leaving it in. Pretty sure I changed it to c and received an equal amount of errors, will try now
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.
I have tried your code and it works if you change it to a small c and also define the issue (if you don't use the script in a post function or listener).
Also, is the field you want to update a User Picker (multiple options)? In that case you will need to get the fields configuration.
def cf = customFieldManager.getCustomFieldObject("Approvers")
def cfConfig = cf.getRelevantConfig(issue)
def customFieldOptions = ComponentAccessor.optionsManager.getOptions(cfConfig)
def changeHolder = new DefaultIssueChangeHolder()
def fieldOption = customFieldOptions.find {it.value == userInGroup[0]} // the user in this case will need to be retrieved from the usersInGroup list
cf.updateValue(null, mutableIssue, new ModifiedValue(mutableIssue.getCustomFieldValue(cf), [userInGroup]), new DefaultIssueChangeHolder())
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I intend to use it in a Post function as part of our change management overhaul, I want to use the native Service Desk approval functionality instead of permissions and custom emails.
I really detest that you have to be a Groovy expert in order to use Scriptrunner with any kind of efficiency.
Wish they'd make it easier, I expect they're keeping people in jobs with the knowledge barrier.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
In this case the context of the object will be passed on by the post function so you don't need to define it in the script.
To be fair there is an extensive knowledge base and lots of examples of how to use it but I understand that it might be difficult to gauge how much effort is involved into automating tasks with Scriptrunner.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Well the thing is it's always a case of having to Google your ass off, eventually find some example, then spend hours more trying to find out what else it needs to modify it to your needs.
Would you be able to post the completed example of how to use it in a post function? I noticed it moaning about the usersInGroup line so I assume that needs defining too
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I have a similar example but it's for Single User Picket custom field. I changed it slightly to use your variables:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.MutableIssue
def groupManager = ComponentAccessor.getGroupManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def group = groupManager.getGroup("Automations")
def usersInGroup = groupManager.getUsersInGroup(group)
def cf = customFieldManager.getCustomFieldObject(10233) //Custom field ID
def cfConfig = cf.getRelevantConfig(issue)
def customFieldOptions = ComponentAccessor.optionsManager.getOptions(cfConfig)
def changeHolder = new DefaultIssueChangeHolder()
def fieldOption = customFieldOptions.find {it.value == usersInGroup[0]}
cf.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(cf), usersInGroup[0]), new DefaultIssueChangeHolder()) // update CM Approvers with users
Basically this add the first user in the group in the Approvers custom field.
The solution will need to be modified if you are adding multiple users.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Looks like it's still failing even without groovy error.
Should this one be a lister or post function, currently trying to do it as a post function.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Steve, as I mentioned before this script will update a single user picker field. If you are trying to update a multi user picker we will need to make some small changes.
Is there anything in the logs that lets you know it's failing?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi
Jira Misc Workflow Extension plugin has come to the rescue here. I raised it with them and they simply told me to use a set field value post function
Groovy Expression
ComponentAccessor.groupManager.getUsersInGroup("my-group")
and it's now doing exactly what I want :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Happy you got it working.
Not sure how this is different from the code I sent you though, as this just returns the members and doesn't update the field.
Please also note that you provided us with a code snippet and the errors and not specified the requirements.
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.