Hi Community,
The idea is, have on Jira only one field "Approver" created, and this field by default allows you to select one of the all users that you have in Jira.
Until here all is fine but now I want depends of the request type that the user select in the customer portal, show only the users of the one group.
I am traying doing something like this:
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.user.ApplicationUser
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours
FormField segAprueba = getFieldByName("Approver")
segAprueba.setLabel("Why do you need this?")
segAprueba.setDescription("Tell us why you want this.")
def users = ComponentAccessor.groupManager.getUsersInGroup("AAutomatizaciones JIRA")
ArrayList finalUsers = new ArrayList()
for (user in users){
finalUsers.add(user.key)
}
segAprueba.setFieldOptions(finalUsers)
But this doesn't work, have any ideas?
Adrián.
Hey there Adrián!
Hopefully I'm not too late on this post! I've been toying around with this for the better part of a day and, using the approach described above, haven't been able to get this working either. I had suggested that you could set the field options of the user-picker, but I think I may have been off in that assumption. "Picker" fields are special in that they are dynamic; meaning the selectable options will change depending on what you type in. So, this makes it practically impossible to easily set their selectable options in any way.
However, I don't want to leave you without any option whatsoever. Through my messing around, I've come up with a method using ScriptRunner that could possibly work for your use-case. In short, I was able to find a way to dynamically populate the selectable options of a field depending on the request type. I accomplished this using two things, Behaviour select list conversions and Script REST Endpoints. You can get more information on these features through the documentation, but essentially the idea is that we convert a text field to a select field and populate it using the results of a REST Endpoint (which accepts a request type name as a query parameter) that returns a list of users. Below are some steps and code to accomplish this.
Steps:
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import groovy.json.JsonBuilder
import groovy.transform.BaseScript
import javax.ws.rs.core.MultivaluedMap
import javax.ws.rs.core.Response
import com.atlassian.jira.component.ComponentAccessor
@BaseScript CustomEndpointDelegate delegate
setUserOptions(httpMethod: "GET") { MultivaluedMap queryParams ->
def requestType = queryParams.getFirst("requestType") as String
def rt = [:] //initialize return value
def users = null
switch(requestType) //update user values per request type
{
case "IT help":
users = ComponentAccessor.groupManager.getUsersInGroup("IT help approvers")
break
case "<other request type>":
users = ComponentAccessor.groupManager.getUsersInGroup("<other group name>")
break
//default:
//etc...
}
rt = [
items: users.collect{user ->
[
value: user.name,
label: user.name,
]
}
]
return Response.ok(new JsonBuilder(rt).toString()).build();
}
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.scriptrunner.canned.jira.utils.servicedesk.ServiceDeskUtils
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours
def requestTypeId = b.requestTypeId
def serviceDeskId = b.serviceDeskId
def requestType = ServiceDeskUtils.getRequestType(serviceDeskId as String,requestTypeId as String)
log.debug("Request Type: ${requestType.name}")
def segAprueba = getFieldByName("Approver")
segAprueba.convertToSingleSelect(
[
ajaxOptions: [
url : getBaseUrl() + "/rest/scriptrunner/latest/custom/setUserOptions",
//query: false,
data: [
requestType : requestType.name,
],
formatResponse: "general"
]
])
Try that out and let me know if it works for your purposes. :D
Best,
Aidan
Hi @Aidan Derossett [Adaptavist],
I don't have time to prove it until Christmas finish but this looks like I want.
Thanks a lot, Merry Christmas and a happy new year.
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.