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

Durga prasad panda September 26, 2019

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

2 votes
Answer accepted
Ravi Sagar _Sparxsys_
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 Leaders.
September 26, 2019

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

Durga prasad panda September 26, 2019

Hi @Ravi Sagar _Sparxsys_ 

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

Packialakshmi Subramanian October 28, 2020

@Ravi Sagar _Sparxsys_ 

I added the same beahviour code for workflow condition - ( create action)  and mapped the corresponding project. it is not making the field "Issue" as mandatory.

I am able to make the Linked issue required field but the associated field "Issue" (with link types) not working on create transition. We want to force the user to enter value (actually link some issue to the issue being created) for linked issues field upon creation.

Also, Tried the following link . but no Luck - https://community.atlassian.com/t5/Jira-questions/Make-quot-Issue-Link-quot-a-required-field-is-not-being-enforced/qaq-p/310724

Please advise.

0 votes
Answer accepted
Amit Girme September 26, 2019

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

Durga prasad panda September 26, 2019

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