Forums

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

How to get the current issue key before creation in behaviour plugin?

Krithica Gowri Shankar
Contributor
March 21, 2017

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.MutableIssue

def issue = ComponentAccessor.getIssueManager().getIssueByCurrentKey("DC_CM-1893");

def customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(10731L);//customfield id
def appt = getFieldById("customfield_10729")
if(issue.getCustomFieldValue(customField) =~ 'JIRA')
{

appt.setHidden(true);
}
else
{ appt.setHidden(false);

}

We use the above script. In the above code the validation works with  existing issue " DC_CM-1893".

Whereas we need to use the behaviour for current issue in create screen. 

Not able to get the current issue key and apply validation.

Instead of existing issue we need the current issue which is about to create.

Please let us know how to achieve this.

2 answers

1 accepted

0 votes
Answer accepted
Nic Brough -Adaptavist-
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.
March 21, 2017

You can't.

The issue does not have a key until after the issue has been created - this effectively happens in post-functions that occur after the completion of the screen.

0 votes
Krithica Gowri Shankar
Contributor
March 21, 2017

Thanks Nic Brough,

We usually do hides the fields according to the other field values. There we don't need to mention the issue key, and it is taking automatically, whereas for the cascading select the same logic is not working. So we tried in the above script where we need the issue key.

This below script is working for normal select list and text field, but not for Cascade select list.

def Virtual = getFieldByName("Virtual Team")                                                                                                       def prcd = getFieldByName("Proof of Concept Driver")                                                                    log.debug("Virtual" + Virtual.getValue())

if (Virtual.getValue() =~ "Product Path")

{

prcd.setHidden(false);

prcd.setRequired(true);

}

else

{

prcd.setHidden(true);

 prcd.setRequired(false);

}

Please help.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events