Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Groovy script problem

Marcela Junyent
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
October 23, 2019

I copy the following copy from adaptavist library:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueFieldConstants
import com.atlassian.jira.issue.Issue

// the name of the field to copy
final String fieldNameToCopy = "Priority";

// leave blank to copy from the last linked issue (regardless the link type)
final String issueLinkTypeName = "Blocks"

def fieldManager = ComponentAccessor.fieldManager

def fieldToCopy = fieldManager.allAvailableNavigableFields.find { it.name == fieldNameToCopy }
if (!fieldToCopy) {
log.info "Could not find field with name $fieldNameToCopy"
return
}

def linkedIssues = ComponentAccessor.issueLinkManager.getOutwardLinks(issue.id)
if (!linkedIssues) {
log.info "There are no linked issues"
return
}

if (issueLinkTypeName && !(issueLinkTypeName in linkedIssues*.issueLinkType*.name)) {
log.info "Could not find any issue, linked with the $issueLinkTypeName issue type"
return
}

def linkedIssue = issueLinkTypeName ?
linkedIssues.findAll { it.issueLinkType.name == issueLinkTypeName }.last().destinationObject :
linkedIssues.last().destinationObject

def fieldToCopyId = fieldToCopy.id

switch (fieldToCopyId) {
case fieldManager.&isCustomFieldId:
def customField = ComponentAccessor.customFieldManager.getCustomFieldObject(fieldToCopyId)
def linkedIssueCustomFieldValue = linkedIssue.getCustomFieldValue(customField)
issue.setCustomFieldValue(customField, linkedIssueCustomFieldValue)
break

case IssueFieldConstants.COMPONENTS:
def commonComponents = linkedIssue.components.findAll { it.name in issue.components*.name }
issue.setComponent(commonComponents)
break

case IssueFieldConstants.FIX_FOR_VERSIONS:
def commonFixedVersions = linkedIssue.fixVersions.findAll { it.name in issue.fixVersions*.name }
issue.setFixVersions(commonFixedVersions)
break

case IssueFieldConstants.AFFECTED_VERSIONS:
def commonVersions = linkedIssue.affectedVersions.findAll { it.name in issue.affectedVersions*.name }
issue.setFixVersions(commonVersions)
break

default:
issue[fieldToCopyId] = linkedIssue[fieldToCopyId]
}

 

But I get unknown methods error. Don't know why...  

Someone could help me. thanks

 

3 answers

1 accepted

Suggest an answer

Log in or Sign up to answer
0 votes
Answer accepted
Yogesh Mude
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
July 23, 2018

Hi @Dan27,

As mentioned by @informatikus just you need to remove the particular issue type from the issue type scheme of that project.

Let me ask one thing what do you mean by 

I want this issue type will create only from workflow,

Dan27
Contributor
July 23, 2018

Hi @Yogesh Mude ,

I have a workflow that create automatically this issue type- So I need it in the scheme.

I don't want that users (in all types) can create this issue type by create screen- So I need to hide it from this screen.

Yogesh Mude
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
July 23, 2018

Nope, there is no way to hide the issue type from the create screen unless until you can not remove this from the scheme.

And you can't restrict users on basis of issue type while creating issues.

Dan27
Contributor
July 23, 2018

@Yogesh Mude and readonly is an option??

Yogesh Mude
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
July 23, 2018

So you need to provide the access to perticular group/role as a  Browse project permission for that specific project so that the users belong to these group/role they can only see the issues but not able to create it.

Dan27
Contributor
July 24, 2018
0 votes
Lennart
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
July 23, 2018
No text
0 votes
Lennart
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
July 23, 2018

You say you would like to remove the option to choose a specific issue type?

Why go the hard way scripting out this option instead of just removing the issue type from the project (scheme wise)?

Dan27
Contributor
July 23, 2018

Hi @informatikus ,

I want this issue type- but I want this issue type will create only from workflow, and not from the create screen.

TAGS
AUG Leaders

Atlassian Community Events