Hi
How map components to a Request Type for a Service Desk project? We have many components for our Service Desk some are not valid for some Request Type. For example, technical support-related components are not valid for Sales. If customers select "Sales" Request Type it should only display "Purchase" and "Return". If Technical Support then it should display other components. I found a script it works fine with issue types but I don't know how to make it work with Request Type. I don't want to hide components from the backend, just from the customer portal.
import com.atlassian.jira.config.IssueTypeManager
import com.atlassian.jira.component.ComponentAccessor
Map validComponentNameByType = ["Task":
["Purchase","Return"]
] //Change Task issue type to "Sales" Request Type
def project = issueContext.projectObject
def issueType = issueContext.issueType.name
def component = getFieldById("components")
if(issueType && validComponentNameByType[issueType]){
def validComponent = project.getComponents().findAll{it.name in validComponentNameByType[issueType]}
component.setFieldOptions(validComponent)
}
I'll be thankful if someone helps me update the script for Request Type.
Thank you
Behaviours comes with a "getRequestTypeName()" method that you can call.
Armed with that, you can convert that script to something quite simple:
Map validComponentNamesByRequestType = [
"Sales": ["Purchase", "Return"],
]
if (!requestTypeName) {
//no requestTypeName is available at this time (also happens when creating issues from Jira instead of the portal
return
}
def validComponentNames = validComponentNamesByRequestType[requestTypeName]
def validComponent = issueContext.projectObject.components.findAll { it.name in validComponentNames }
getFieldById("components").setFieldOptions(validComponent)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi, @PD Sheehan sorry to bother you. How can I not show these components in the Tech Support request type? Right now it is working fine with Sales where I can see only components that I add in the script, but is there a way that those components are not shown in any other request type, like Tech Support. In Tech Support and another request type, I can see "Purchase" and "Return" too. Right now in Tech Support and other request types, I can see all components, but I don't those components display there. Is there any way that any components display in Sales request type, those components should not display in any other request type?
Thank you for your help.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Just to confirm:
Sales Request Type => only show "Purchase" and "Return" component in the list
All other request type => Hide "Purchase" and "Return" components from the list
You could just add all your other request types here:
Map validComponentNamesByRequestType = [
"Sales": ["Purchase", "Return"],
"Tech Support": ["ComponentA", "ComponentB", ...],
...
]
Or if you don't want to have to update this script each time you add components or request tyes, you can have something like this:
Map exclusiveComponentByRequestType = [
"Sales": ["Purchase", "Return"],
]
if (!requestTypeName) {
//no requestTypeName is available at this time (also happens when creating issues from Jira instead of the portal
return
}
def validComponents = issueContext.projectObject.components
if (exclusiveComponentByRequestType.containsKey(requestTypeName)) {
//this is the same as earlier script version. Just with different variable names
def validComponentNames = exclusiveComponentByRequestType[requestTypeName]
validComponents = validComponents.findAll { it.name in validComponentNames }
} else {
//for the case where the request type is not in the exclusionlist, we look at each request types that have exclusions and we remove those items from the valid list
exclusiveComponentByRequestType.each{rtName, componentNames->
if(rtName != requestTypeName){
validComponents.removeAll { it.name in componentNames }
}
}
}
getFieldById("components").setFieldOptions(validComponents)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you so much @PD Sheehan, I tried the first method by mapping other components with other request types and it didn't work. I just realized I didn't add those request type I Mapping list, I had just Sales one.
Your second script would work better for me. Thank you again for helping. have a nice weekend.
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.