Forums

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

How can I access an issue picker object's issue id?

Mick Lovell
Contributor
August 9, 2019

I have an issue picker field called 'Linked issue selection'.  I'm trying to link the current issue to the issue selected in the picker field via a script.  Here is the code:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.issue.link.IssueLinkManager
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.customfields.manager.OptionsManager


def id = issue.getId()

def issuePickerField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Linked issue selection")
def issuePickerFieldValue = issue.getCustomFieldValue(issuePickerField) as Issue
def issuePickerFieldIssueId = issuePickerFieldValue.getId()


def linkManager = ComponentAccessor.getIssueLinkManager()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser() as ApplicationUser

linkManager.createIssueLink(id, issuePickerFieldIssueId, 10003, 1, user)

 

The error rendered states: 

"Error

We were unable to submit your request. Please refresh the page and try again. Note that this will clear your request details.

If you have already tried again, contact your Jira Administrator."

 

This post-function is located in the create transition as the 5th post-function.  When the post-function is disabled the issue is created with no error.

 

Thank you

 

2 answers

1 accepted

0 votes
Answer accepted
Mick Lovell
Contributor
August 12, 2019

Thanks for your help Jack,

 

I was able to solve the problem by declaring the issuePickerFieldValue variable as a string.  Then using that variable as the issue key to declare an issue object variable.  

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.search.SearchProvider
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.issue.link.IssueLinkManager
import com.atlassian.jira.ComponentManager


def id = issue.getId()
def issueManager = ComponentAccessor.getIssueManager()
def issuePickerField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_12934")
def issuePickerFieldValue = issue.getCustomFieldValue(issuePickerField) as String
def pickedIssueAsIssue = issueManager.getIssueObject(issuePickerFieldValue)
def issuePickerFieldIssueId = pickedIssueAsIssue.getId()


def linkManager = ComponentAccessor.getIssueLinkManager()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser() as ApplicationUser

linkManager.createIssueLink(id, issuePickerFieldIssueId, 10003, 1, user)

Jack Nolddor _Sweet Bananas_
Atlassian Partner
August 13, 2019

Nice!

0 votes
Jack Nolddor _Sweet Bananas_
Atlassian Partner
August 10, 2019

Hi Mick,

What is the order of this postfunction? Could you try it to send it to the bottom and see if it works?

If not, please provide us the error thrown in the log when the postfunction is executed, this would help to underestand where the problem is.

Regards.

Mick Lovell
Contributor
August 12, 2019

Hello Jack,

The postfunction is at the bottom in the 5th position of the create transition.  The log shows:

"Time (on server): Mon Aug 12 2019 09:38:34 GMT-0400 (Eastern Daylight Time)

The following log information was produced by this execution. Use statements like:log.info("...") to record logging information.

No logs were found for this execution."

 

It appears to execute without failure from the logs, but the customer portal shows the error posted above, and the new issue is not linked to the issue selected with the issue picker field.

 

Thank you.

Jack Nolddor _Sweet Bananas_
Atlassian Partner
August 12, 2019

Are there any other custom post-function or validator?
Is the issue created if you remove this custom postfunction?

Try to figure out what the problem is by searching in the atlassian-jira.log file instead

Hint: You can view the location of the atlassian-jira.log in the 'File Paths' section of the system information page.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events