Hi,
We're using Jira service desk for multiple clients (in one project) and have a custom field called "Client". I would like to set this field automatically in a post-function depending on which user group the user is a member of, e.g.
if (user.inGroup("Client A")) { Client = "Client A" } elseif if (user.inGroup("Client B")) { Client = "Client B" } ...
I've tried using user properties on the user and copying them over as a post-function, but this is going to be tedious and error prone to maintain. I've tried a conditional script runner ("Set Field Value to constant or Groovy expression) but I would need to write one per client, and besides, I can't get the conditional logic for group membership to work.
Other than writing a bespoke groovy script (which is beyond my skills at the moment, and would also cause a maintenance problem) can anyone think of a good way to do this?
thanks,
Mark.
I think a custom post function should do the work for you
Try the following, with the appropriate changes for your case. I have not tested so possibly there bugs in it.
import com.atlassian.jira.component.ComponentAccessor; import com.atlassian.jira.issue.CustomFieldManager; import com.atlassian.jira.issue.fields.CustomField; import com.atlassian.jira.issue.IssueManager; import com.atlassian.jira.issue.Issue; import com.atlassian.jira.issue.MutableIssue; GroupManager groupManager = ComponentAccessor.getGroupManager(); CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager(); //custom field client id = xxxxx CustomField customField_client = customFieldManager.getCustomFieldObject( xxxxx ); if (groupManager.isUserInGroup(issue.getCustomFieldValue( customField_client ), String groupname)) { issue.setCustomFieldValue(customField_client, value) }
Related documentation for groovy script runner plugin is here and is very well written and updated.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I still think the easiest way is using groovy :). If you have a common naming patter for the clinet user groups then it will be possible to make this work and not to require maintanance. You'll get help with the script - I'm sure a couple of people will be able to provide you with samples.
So is there a common naming pattern for the groups ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
yeah, good point. It could be more or less maintenance free, if you just set the group according to whatever group the user is in, excluding jira-users. Or make all your client groups begin with Client...
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.
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.