Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How map componenets to Request Type using ScriptRunner?

Shah Baloch February 14, 2022

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

1 answer

1 accepted

Suggest an answer

Log in or Sign up to answer
0 votes
Answer accepted
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 14, 2022

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)
Shah Baloch February 16, 2022

Thank you so much @Peter-Dave Sheehan 

Shah Baloch February 18, 2022

Hi, @Peter-Dave 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.

Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 18, 2022

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)
Like Shah Baloch likes this
Shah Baloch February 18, 2022

Thank you so much @Peter-Dave 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.

TAGS
AUG Leaders

Atlassian Community Events