Hello All,
We have Organized Jira Service desk Request Types to multiple Groups to appear in the customer portal Ex: Jira, Confluence, Bitbucket and Bamboo.
Each Group has multiple Request types For Example: Jira has following Request types New Account, modify Field, Edit Project Reporting and Bug.
Group confluence has following Request types New Confluence Space, Additional functionality, Bug and Performance
For Groups Jira and confluence has following fields on Customer portal Summary, Description, Attachment and Servers. Servers custom field has following Options Server1, Server2, Server3 and Server4.
Now we want to Restrict the values on the Servers field depend on the Request Type group. Ex - If user selects a Group Jira and Request name Bug on the customer portal Servers field
has to show following options Server1 and Server2 and same way if user selects Confluence group and Request name Bug Servers field has to show only following options Server 2 and Server 3.
To achieve this we have added below script in the behavior and mapped to Jira service desk project and All Request Types. But Servers custom field is showing all 3 options in Groups Jira , Confluence, BitBucket and Bamboo in Bug request type which we added in the script.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.customfields.option.Option
def issueField = getFieldByName("Servers")
// Get the current user
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def optionsManager = ComponentAccessor.getOptionsManager()
def customField = customFieldManager.getCustomFieldObject(issueField.fieldId)
def config = customField.getRelevantConfig(getIssueContext())
// Get predifined customField options
def options = optionsManager.getOptions(config)
def groupProjectsMap = [
'Jira': ['Server1','Server2'],
'Confluence': ['Server3'],
]
def optionsToSet = []
log.debug("Map: ${groupProjectsMap}")
for (r in groupProjectsMap) {
def option = options.findAll {it.value in r.value} as List<Option>
optionsToSet.add(option)
}
log.debug("Options: ${optionsToSet.flatten()}")
issueField.setFieldOptions(optionsToSet.flatten())
Please help!
Thanks in advance,
Ch
First of all this lines below does the make much sense.
for (r in groupProjectsMap) {
def option = options.findAll {it.value in r.value} as List<Option>
optionsToSet.add(option)
}
What you need to do find out what Request type is selected and do and if else code block
if(requestType.value == "Jira"){
def option = ['Server1', 'Server2']
}else if(requestType.value == 'Confluence'){
def option = ['Server2', 'Server3']
}
optionsToSet.add(option)
issueField.setFieldOptions(optionsToSet.flatten())
Let me know if it works for you.
Hi @brbojorque
As your suggestion modified the script. It showing below error.
Error - The variable [requestType] is undeclared.
Below is the script which i modified:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.customfields.option.Option
def issueField = getFieldByName("Servers")
// Get the current user
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def optionsManager = ComponentAccessor.getOptionsManager()
def customField = customFieldManager.getCustomFieldObject(issueField.fieldId)
def config = customField.getRelevantConfig(getIssueContext())
// Get predifined customField options
def options = optionsManager.getOptions(config)
def groupProjectsMap = [
'Jira': ['Server1','Server2'],
'Confluence': ['Server3'],
]
def optionsToSet = []
log.debug("Map: ${groupProjectsMap}")
if(requestType.value == "Jira"){
def option = ['Server1', 'Server2']
}else if(requestType.value == 'Confluence'){
def option = ['Server2', 'Server3']
}
optionsToSet.add(Option)
issueField.setFieldOptions(optionsToSet.flatten())
Attaching screen shots for your reference:
Please let me know if you need any further details.
Thanks in advance,
Manikanta
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @[deleted] ,
Please check the solution, I tried to scour the internet in order for me to get the current request type used in the service desk and I can't for the life of me get the solution.
Here's the workaround, it will determine the group by checking the issuetype of the current request.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.customfields.option.Option
def issueField = getFieldByName("Server")
// Get the current issue type
def issue = getIssueContext()
// Get the current user
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def optionsManager = ComponentAccessor.getOptionsManager()
def customField = customFieldManager.getCustomFieldObject(issueField.fieldId)
def config = customField.getRelevantConfig(getIssueContext())
def options = [:]
def listOpt = []
if(issue.getIssueType().name == 'Service Request'){ // IssueTypes inside Confluence Group
listOpt = ["Server 1", "Server 2"]
}else if (issue.getIssueType().name == 'IT Help'){ //IssueTypes inside Jira Group
listOpt = ["Server 3", "Server 4"]
}
options = optionsManager.getOptions(config).findAll{ it.value in listOpt }
issueField.setFieldOptions(options)
Caveat
If you have multiple Issuetype mixed in both groups this will not work, it must be that the issuetype is unique to each group.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for taking time and helping me. Will it be possible to get Request type Groups in Script Runner behavior?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @[deleted] ,
By using RequestTypeService and RequestTypeGroups clases, it is easy to fetch the list of groups and request types.
The problem is getting the Request type of the current Context, without that piece of information the list of request types and groups does not really matter.
I'd have to do further research for this.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for the help again @brbojorque
Please let me know if find any solution. I will also try to find for solution on my end.
Thanks again,
ch
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @[deleted] ,
I think I have found the solution in getting the request type.
Please take a look at this example.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for the link, tried with the below script it is not working and it is showing below error.
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.servicedesk.api.requesttype.RequestTypeService
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.opensymphony.workflow.WorkflowContext
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.customfields.option.Option
import com.atlassian.servicedesk.api.requesttype.RequestType
import com.atlassian.jira.user.ApplicationUser
@WithPlugin("com.atlassian.servicedesk")
RequestTypeService requestTypeService = ComponentAccessor.getOSGiComponentInstanceOfType(RequestTypeService)
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
ApplicationUser user = ComponentAccessor.getUserManager().getUserByName(ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser().name)
RequestType getRequestType = requestTypeService.getRequestTypeForIssue(user, underlyingIssue).right().get()
def issueField = getFieldByName("Server")
def customFieldManager = ComponentAccessor.getCustomFieldManager()
String requestTypeName = getRequestType.getName()
def optionsManager = ComponentAccessor.getOptionsManager()
def customField = customFieldManager.getCustomFieldObject(issueField.fieldId)
def config = customField.getRelevantConfig(getIssueContext())
def options = [:]
def listOpt = ["Server1", "Server2"]
def listOpt1 = ["Server3", "Server4"]
if ("Jira".equals(requestTypeName)) {
options = optionsManager.getOptions(config).findAll{ it.value in listOpt }
issueField.setFieldOptions(options)
}
else {
options = optionsManager.getOptions(config).findAll{ it.value in listOpt1 }
issueField.setFieldOptions(options)
}
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.
Recommended Learning For You
Level up your skills with Atlassian learning
Learning Path
Get the most out of Jira Service Management
Solve customer problems efficiently and deliver outstanding service experiences.
Learning Path
Adopt ITSM practices to deliver exceptional service
Become familiar with the principles and practices that drive ITSM. Then, learn how to configure and use Jira Service Management to implement them.
Atlassian Certified Associate
Jira Service Management Agent Essentials certification
Prove you know what's essential to providing efficient and resolution-focused service in Jira Service Management.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.