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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,455,400
Community Members
 
Community Events
175
Community Groups

How map componenets to Request Type using ScriptRunner?

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

0 votes
Answer accepted

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)

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.

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

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.

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events