Hello Team,
I have a service desk project so on create transition I have added a scripted postfunction that to auto clone issues in 2 different destination projects.
Here I need to apply a condition like If the JSD ticket components has 1 value then it has to clone one ticket in destination project
If Component has 2 or 3 or 4 values it has to create those many tickets in the Destination projects
can anyone please help with the scripted postfunction
Thanks,
Phani
Hi @Kumar,
I've written a custom script to clone issue depends on the size of components selected for the current issue
NOTE: this script clones no. of issues to single Target project for now, you need to modify script to clone in another project as well
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import org.apache.log4j.Level
import org.apache.log4j.Logger
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def linkMgr = ComponentAccessor.getIssueLinkManager()
def issueManager = ComponentAccessor.getIssueManager()
def searchService = ComponentAccessor.getComponent(SearchService)
def issueFactory = ComponentAccessor.getIssueFactory()
def PROJECT_KEY_TO = "TARGET" // Target Project key
def projectTo = ComponentAccessor.getProjectManager().getProjectByCurrentKey(PROJECT_KEY_TO)
def comp = issue.getComponents() as List
for(int i = 0; i< comp.size(); i++){
def newIssue = issueFactory.cloneIssue(issue)
newIssue.setProjectObject(projectTo)
Map<String,Object> newIssueParams = ["issue":newIssue] as Map<String,Object>
issueManager.createIssueObject(currentUser, newIssueParams)
linkMgr.createIssueLink(newIssue.id, issue.id, 10001, 1, currentUser) // Here 10001 is my server's Clone link type ID. check in your server & replace it with valid id
log.info("Issue ${newIssue?.key} cloned to project ${projectTo.key}")
}
BR,
Leo
Hello @Leo
Thanks for your script it’s working as I expected a small correction to avoid static error
linkMgr.createIssueLink(newIssue.id, issue.id, 10001 as Long, 1 as Long, currentUser)
and once again thanks for your script.
Thanks,
Phani
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If I get you right, you are using the default clone issue postfunction provided by scriptrunner, which can only clone one issue.
If you know all available Components, you could add one postfunction for each component with the condition:
def components = issue.components.toList()
components?.name.contains('MyComponent')
The better solution would be to write a custom-script that loops over all components and clones the issue for each component.
I dont have a working script for that but found this:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Leonard Chew
Actually I can apply condition like
if “some field” = “X” option the create a issue
but here I need give like
component= “x && y && z”
It has to create a 3 tickets for that how can I give the condition to that
can you please help me here with the script
Thanks,
Phani
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Do you have any line of code?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Damian Wodzinski
No didn’t have any Line of code.
i just used the I used the postfunction which is provided by ScriptRunner for autoclone
thanks,
phani
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.