It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Need help on making issue link mandatory on create and edit (if there is not links present already)

Hi

I am very new to scripting. I have a requirement to set Issue linking mandatory while creating an issue.
I have to set Linked issues to "is part of" (inward link) and also in issues field, it should only show tickets from that same project only.

However to make it mandatory I used behavior and added below code.

getFieldById("issuelinks-linktype").setFormValue("is part of").setReadOnly(true)
getFieldById('issuelinks-issues').setReadOnly(false)


for some part, it is working fine. It is making issue linking mandatory while creating the issue also link type is set to "Is part of"

But the main problem is whenever I am trying to edit one issue, at that time even if there is already an existing link it is again asking to fill in the linking issue-issue filed.

and is it possible to show issue from the same project only in that issue filed?

any help would be highly appreciable. 

2 answers

2 accepted

1 vote
Answer accepted

Hi @Durga prasad panda 

Start with this piece of code.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.link.IssueLink

def links = getFieldById('issuelinks')
def linksValue = links.getValue()
def linkType = getFieldById("issuelinks-linktype")
def linkTypeValue = linkType.getValue()
def linkField = getFieldById('issuelinks-issues')
def linkFieldValue = linkField.getValue()

def existingLinks = ComponentAccessor.getIssueLinkManager().getInwardLinks(underlyingIssue?.getId())

if (existingLinks?.size() == 0 && linkTypeValue == "is part of") {

links.setRequired(true)

} else {

links.setRequired(false)

}

It should make the link field required on creation and on edit later when there are no existing links but the code will not work when user clicks on the link option under the more or in the link section, for that you will have to write your own JavaScript.

Ravi

Hi @Ravi Sagar -Adaptavist- 

Is there way to restrict which issues from which project/same project can be selected only in the linked issue?

by the way thanks the above solution worked like charm

0 votes
Answer accepted

Use the behaviour's Guide Workflow
Add a new condition of workflow action of Create (1) for the field

Thanks @Amit Girme for the reply. It is also working but the only thing is it is not checking for the links in the edit field. :)

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Jira

The add-in you’ve been waiting for: Jira Cloud for Excel 🙌

Introducing Jira Cloud for Excel Here at the product integrations team at Atlassian, we are thrilled to announce the new Jira Cloud for Excel add-in! This add-in lets you export Jira data directly ...

864 views 6 24
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you